oleppedersen
New Member
- Joined
- Mar 23, 2013
- Messages
- 13
I am running through a bunch of workbooks, opening them, identifying one sheet in each book and want to copy the sheet to an array.
I have declared the range earlier:
Dim rT(10) as Range
...
' Run through the number of files from 1 to antT (which is declared and working)
For y = 1 To antT
' This works fine, the book is opened
Set wbT
= Workbooks.Open(MappeFra & filT
& ".xlsx")
' This works fine, the sheet is defined as no 1, which I can tell by testing with a messagebox that returns the name
Set wsT
= wbT
.Sheets(1)
' Counting the number of lines in the sheet. This also works fine as the srT
variabile is filled the number of last row
wsT
.Activate
With ActiveSheet
srT
= .Cells(.Rows.Count, "A").End(xlUp).Row
End With
' This is just a way to see if .Range(Område) in the next command works better than .Range("A1:L" & srT
) (no reason it should work better, and it did not
Område = "Al:L" & Str
' Here is where I get the runtime error:
Set rT
= wsT
.Range(Område)
------
Normally, this would populate the range variable with the range from the worksheet, which I then transfer to the array (and can close the workbook, if I want to).
But why doesn't this work? I am probably missing something really simple here.
I have seen through quite a few run time error posts, but nothing completely similar comes up.
I have declared the range earlier:
Dim rT(10) as Range
...
' Run through the number of files from 1 to antT (which is declared and working)
For y = 1 To antT
' This works fine, the book is opened
Set wbT


' This works fine, the sheet is defined as no 1, which I can tell by testing with a messagebox that returns the name
Set wsT


' Counting the number of lines in the sheet. This also works fine as the srT

wsT

With ActiveSheet
srT

End With
' This is just a way to see if .Range(Område) in the next command works better than .Range("A1:L" & srT

Område = "Al:L" & Str

' Here is where I get the runtime error:
Set rT


------
Normally, this would populate the range variable with the range from the worksheet, which I then transfer to the array (and can close the workbook, if I want to).
But why doesn't this work? I am probably missing something really simple here.
I have seen through quite a few run time error posts, but nothing completely similar comes up.