StevenHolden
New Member
- Joined
- Dec 19, 2011
- Messages
- 2
Hi All
I have this code which works well and consistently, but I can't seem to use the Cells method without the error. I have no idea why, so can anyone tell me off the top of their head what the deal is? Hopefully someone can easily point out my stupidity to me...
Basically I am trying to declare 2 ranges which contain a set of IDs. One is on the worksheet the code is launched from "ElmTemps", the other is not. The troublesome range is "rNodeIDs"
The code which works:
The code which breaks:
The code is exactly the same except for the rNodeIDs definition.
If the bad line is commented the rElmIDs is Set correctly.
My question is why I cannot use the Cells(i,j) method? I assume it is because it is on a different worksheet, but I thought explicitly declaring everything should allow this.
I can get around it no problem by building the "A8:Axxx" string as I need, but it is nowhere near as useful or clean as the cells approach.
Can anyone clear up this seemingly fundamental hole in my knowledge?
Thanks in advance!
I have this code which works well and consistently, but I can't seem to use the Cells method without the error. I have no idea why, so can anyone tell me off the top of their head what the deal is? Hopefully someone can easily point out my stupidity to me...
Basically I am trying to declare 2 ranges which contain a set of IDs. One is on the worksheet the code is launched from "ElmTemps", the other is not. The troublesome range is "rNodeIDs"
The code which works:
Code:
Dim wbkCurrent As Workbook, shtElmTemps As Worksheet, shtNodeTemps As Worksheet 'Setup worksheets
Dim rElmIDs As Range, rNodeIDs As Range 'Setup ranges
Set wbkCurrent = ActiveWorkbook
Set shtNodeTemps = wbkCurrent.Worksheets("NodeTemps")
Set shtElmTemps = wbkCurrent.Worksheets("ElmTemps")
Set rNodeIDs = shtNodeTemps.Range("A8:A1000")
Set rElmIDs = shtElmTemps.Range(Cells(8, 1), Cells(shtElmTemps.UsedRange.Rows.Count, 1))
The code which breaks:
Code:
Dim wbkCurrent As Workbook, shtElmTemps As Worksheet, shtNodeTemps As Worksheet 'Setup worksheets
Dim rElmIDs As Range, rNodeIDs As Range 'Setup ranges
Set wbkCurrent = ActiveWorkbook
Set shtNodeTemps = wbkCurrent.Worksheets("NodeTemps")
Set shtElmTemps = wbkCurrent.Worksheets("ElmTemps")
Set rNodeIDs = shtNodeTemps.Range(Cells(8, 1), Cells(1000, 1))
Set rElmIDs = shtElmTemps.Range(Cells(8, 1), Cells(shtElmTemps.UsedRange.Rows.Count, 1))
The code is exactly the same except for the rNodeIDs definition.
If the bad line is commented the rElmIDs is Set correctly.
My question is why I cannot use the Cells(i,j) method? I assume it is because it is on a different worksheet, but I thought explicitly declaring everything should allow this.
I can get around it no problem by building the "A8:Axxx" string as I need, but it is nowhere near as useful or clean as the cells approach.
Can anyone clear up this seemingly fundamental hole in my knowledge?
Thanks in advance!