vivaruthland
New member
- Local time
- Today, 00:11
- Joined
- Feb 12, 2010
- Messages
- 4
Hi
I want to create a macro with the purpose to call a diferent workbook "Nomedo" and once the workbook is opened the macro should copy and paste a range in this Workbook, but the problem is that the row of the range change, so I can't select a range in this way:
Workbooks().sheets().range("").select
So I expected to use this way
Workbooks().sheets().range(cells(),cells()).select
but it didnt work
Sub actual()
Dim i%, j%, a%, aa%, k%, t%, e%, p%, iEdo%, sNomPP$, sNomShp$, sNomPib$, sNomp$, sNomEdo$, sNome$, iCont%, iConta%, iContb%
Dim aIni%, aFinal%, aPP%, aDatoR%, aInip%
sNomPib = "PIB ESTATAL ANUAL.xlsx"
sNomp = "PIB ESTATAL 06"
sNome = "INGRESO PO"
sNomPP = "PP 1990-2035"
sNomShp = "PP CON CICLO ESTATAL"
p = 11
a = 40
aa = 400
Do While Cells(p, 5) <> ""
iEdo = iEdo + 1 'Cálculo del numero de estados a actualizar
p = p + 1
Loop
'Guarda en memoria los datos para el escenario PIB
aIni = Cells(9, 12)
aFinal = Cells(10, 12)
aDatoR = Cells(11, 12)
aPP = Cells(12, 12)
iContfvar = 521 + (aFinal - 2035)
For e = 1 To iEdo 'esto es para el cada estado
sNomEdo = Cells(e + 10, 5) 'Guarda en -memoria el nombre del Edo
'Abre el archivo estado "e" que se trabajará
Workbooks.Open ("C:\RUTH\RESULTADOS PROYECTO DEMOGRAFIA\ESTADOS\" & sNomEdo), UpdateLinks:=0
Workbooks(sNomEdo).Sheets(sNome).Activate 'Activa la hoja Ingreso PO del archivo estado
'Inserta la variación si se desea insertar un año mayor al 2035
If aFinal > 2035 Then
Workbooks(sNomEdo).Sheets(sNome).Range(Cells(516, 1), Cells(516, 46)).Copy destination:=Workbooks(sNomEdo).Sheets(sNome).Range(Cells(516, 1), Cells(iContfvar, 46))
End If
next e
end sub
I really apreciate if someone could bring me some help
I want to create a macro with the purpose to call a diferent workbook "Nomedo" and once the workbook is opened the macro should copy and paste a range in this Workbook, but the problem is that the row of the range change, so I can't select a range in this way:
Workbooks().sheets().range("").select
So I expected to use this way
Workbooks().sheets().range(cells(),cells()).select
but it didnt work
Sub actual()
Dim i%, j%, a%, aa%, k%, t%, e%, p%, iEdo%, sNomPP$, sNomShp$, sNomPib$, sNomp$, sNomEdo$, sNome$, iCont%, iConta%, iContb%
Dim aIni%, aFinal%, aPP%, aDatoR%, aInip%
sNomPib = "PIB ESTATAL ANUAL.xlsx"
sNomp = "PIB ESTATAL 06"
sNome = "INGRESO PO"
sNomPP = "PP 1990-2035"
sNomShp = "PP CON CICLO ESTATAL"
p = 11
a = 40
aa = 400
Do While Cells(p, 5) <> ""
iEdo = iEdo + 1 'Cálculo del numero de estados a actualizar
p = p + 1
Loop
'Guarda en memoria los datos para el escenario PIB
aIni = Cells(9, 12)
aFinal = Cells(10, 12)
aDatoR = Cells(11, 12)
aPP = Cells(12, 12)
iContfvar = 521 + (aFinal - 2035)
For e = 1 To iEdo 'esto es para el cada estado
sNomEdo = Cells(e + 10, 5) 'Guarda en -memoria el nombre del Edo
'Abre el archivo estado "e" que se trabajará
Workbooks.Open ("C:\RUTH\RESULTADOS PROYECTO DEMOGRAFIA\ESTADOS\" & sNomEdo), UpdateLinks:=0
Workbooks(sNomEdo).Sheets(sNome).Activate 'Activa la hoja Ingreso PO del archivo estado
'Inserta la variación si se desea insertar un año mayor al 2035
If aFinal > 2035 Then
Workbooks(sNomEdo).Sheets(sNome).Range(Cells(516, 1), Cells(516, 46)).Copy destination:=Workbooks(sNomEdo).Sheets(sNome).Range(Cells(516, 1), Cells(iContfvar, 46))
End If
next e
end sub
I really apreciate if someone could bring me some help