Excel - macro para borrar rangos de distintas hojas en un libro de excel

 
Vista:

macro para borrar rangos de distintas hojas en un libro de excel

Publicado por Pablo Gpe. (1 intervención) el 12/01/2019 22:07:14
quiero usar esta macro para borrar un rango de celdas de distintas hojas de un libro de excel pero me marca error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Option Explicit
 
Sub BorrarCeldas1()
Dim oDoc As Object
Dim oRango1 As Object
Dim oRango2 As Object
Dim oRango3 As Object
Dim oRango4 As Object
Dim oRango5 As Object
Dim oRango6 As Object
 
   'Este documento
   oDoc = ThisComponent
   oRango1 = oDoc.getSheets.getByName("Cumbres").getCellRangeByName("G2:J35")
   oRango2 = oDoc.getSheets.getByName("Valle").getCellRangeByName("G2:J35")
   oRango3 = oDoc.getSheets.getByName(Bodega").getCellRangeByName("G2:J35")
   oRango4 = oDoc.getSheets.getByName("Mojarra").getCellRangeByName("G2:J35")
   oRango5 = oDoc.getSheets.getByName("Puerta").getCellRangeByName("G2:J35")
   oRango6 = oDoc.getSheets.getByName("Tortas").getCellRangeByName("G2:J35")

   'Borramos todos los datos en cada rango
   oRango1.clearContents
   oRango2.clearContents
   oRango3.clearContents
   oRango4.clearContents
   oRango5.clearContents
   oRango6.clearContents


End Sub


espero alguien me pueda ayudar gracias de antemano
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

macro para borrar rangos de distintas hojas en un libro de excel

Publicado por JuanC (1237 intervenciones) el 12/01/2019 23:27:00
si usás variable de tipo Object, tenés que asignar mediante Set

Set oRango1 = oDoc.getSheets.getByName("Cumbres").getCellRangeByName("G2:J35")
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Antoni Masana
Val: 4.908
Oro
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

macro para borrar rangos de distintas hojas en un libro de excel

Publicado por Antoni Masana (2478 intervenciones) el 13/01/2019 16:58:54
Además te falta unas comillas entre el paréntesis y la B de Bodega

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Option Explicit
 
Sub BorrarCeldas1()
Dim oDoc As Object
Dim oRango1 As Object
Dim oRango2 As Object
Dim oRango3 As Object
Dim oRango4 As Object
Dim oRango5 As Object
Dim oRango6 As Object
 
   'Este documento
   Set oDoc = ThisComponent
   Set oRango1 = oDoc.getSheets.getByName("Cumbres").getCellRangeByName("G2:J35")
   Set oRango2 = oDoc.getSheets.getByName("Valle").getCellRangeByName("G2:J35")
   Set oRango3 = oDoc.getSheets.getByName("Bodega").getCellRangeByName("G2:J35")
   Set oRango4 = oDoc.getSheets.getByName("Mojarra").getCellRangeByName("G2:J35")
   Set oRango5 = oDoc.getSheets.getByName("Puerta").getCellRangeByName("G2:J35")
   Set oRango6 = oDoc.getSheets.getByName("Tortas").getCellRangeByName("G2:J35")
 
   'Borramos todos los datos en cada rango
   oRango1.clearContents
   oRango2.clearContents
   oRango3.clearContents
   oRango4.clearContents
   oRango5.clearContents
   oRango6.clearContents
End Sub



Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar