I have a problem that prevents me from continuing on my task. With all variables declared, and with the two Workbooks I have to work with opened, I don't manage to make the macro read values from both workbooks. When I use Set wbSource = workbooks.open(sFileName), it returns Nothing to wbSource. The same with all other variables:
Dim nColumnas As Double
Dim nFilas As Double
Dim mec, dis, trans As Double
Dim rnData As Range
Dim i, j As Double
Dim Z As Double
Dim rango As Range
Dim hojaOrigen As String
Dim hojaDestino As String
Dim temporal As Variant
Dim N, Q, E As Long
Dim lo As ListObject
Dim op As Variant
Dim y, m, y_n As Long
Dim hojaGrafico As String
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim QvsE As Worksheet, Requisitos As Worksheet, shEC As Worksheet
Dim myTable As Range
Dim permisos As String
'Filtro
Call AbrirCarpeta(permisos)
Set wbSource = Workbooks.Open(sFileName)
If Err.Number <> 0 Then Debug.Print ("Error number en Libro Formato: " & Err.Number)
If Err.Number = 0 Then Debug.Print ("No ha habido error en libro Formato")
Set wbDest = Workbooks("Nuevo Hoja de cálculo de Microsoft Excel.xlsx")
If Err.Number <> 0 Then Debug.Print ("Error number en Nuevo hoja formato: " & Err.Number)
Workbooks("Nuevo Hoja de cálculo de Microsoft Excel.xlsx").Worksheets("Seleccion_ECs").Activate
Set shEC = wbDest.Worksheets("Seleccion_ECs")
If Err.Number <> 0 Then Debug.Print ("Error number en hoja Seleccion_ECs: " & Err.Number)
Set Requisitos = wbSource.Worksheets("Requisitos Contenedor + ATI")
Set QvsE = wbSource.Worksheets("Curva - QvsE")
'definir bien rango
Q = shEC.Range("1:1").Find(what:="BU Descarga (MWd/tU)", After:=Range("A1")).Column
E = shEC.Range("1:1").Find(what:="Enriq. [%]", After:=Range("A1")).Column
d = Requisitos.Cells(41 + Z, 4).Value
I expect to read values from both worksheets (decimal numbers), but I don't manage to read them. For example, d returns "Empty" as the variable Requisitos is Nothing, even if I connected it to wbSource.Worksheets("Requisitos Contenedor + ATI"), cause wbSource is Nothing. What can I do so it doesn't return Nothing? I previously have the Workbook "Nuevo Hoja de cálculo de Microsoft Excel.xlsx" Activated, but afterwards with Call AbrirCarpeta(permisos), I open the other Workbook "Formato CO-08a (rev.1).xlsx", so I suppose the last one becomes the activated workbook. I usually have errors like 91, 92 or 1004 in Err.number.
Thanks in advance
Workbooks.Open
if the workbook is already open? That's what is causing the problem. – RoryDim i as Double, j As Double
, otherwise only the last one is declared as the type you want it to be and all the others are implicitly declared asVariant
– Stavros JonVariant
. – NacoridOn Error Resume Next
-statement? Remove it and have a look to the first error thrown. What is the content ofsFileName
by the way? – FunThomasQ = [...] After:=Range("A1")).Column
andE = [...] After:=Range("A1")).Column
you should probably fully qualify the Range... – Vincent G