Hi All,
I have the following code:
Here is my debug:Private Sub getrange(ByRef therange As Range, wsheet As Worksheet, strrange As String) Dim rowcount As Long Dim colindex As Integer Dim temprange As Range Dim rowstart As Integer rowstart = Sheet1.therowstart wsheet.Activate Debug.Print wsheet.Name colindex = getcolumn(strrange) rowcount = wsheet.Cells(65536, colindex).End(xlUp).Row If rowcount < Sheet1.therowstart Then rowcount = Sheet1.therowstart End If Debug.Print "sheet1.therowstart: " & Sheet1.therowstart Debug.Print "colindex: " & colindex Debug.Print "rowcount: " & rowcount Debug.Print "value:" & Cells(rowstart, colindex) Set therange = Range(Cells(rowstart, colindex), Cells(rowcount, colindex)) Debug.Print therange(1, 1).Row Debug.Print therange(1, 1).column Debug.Print therange(1, 1).Text
My issue is that somehow, even though I'm telling Excel to go to cells(3,17) on the active sheet (wsheet), it's not seeing a value (or much less anything else). Consequently, I am unable to identify a range.Sheet1
sheet1.therowstart: 3
colindex: 17
rowcount: 3
value:
3
17
I can't even add cells(1,1).select to my code without getting a 1004 error.
Does anyone have any idea what might be causing this and how I can go about fixing it?
Thanks.
Regards,
William
If your code is located in a worksheet code module rather than a normal module, then any reference to Cells or Range that is not explicitly qualified with a worksheet object will refer to the sheet containing the code. (Since that is not the active sheet, you cannot select a cell that way.) You need to use:
for example (or a With...End With block for neatness)Set therange = wsheet.Range(wsheet.Cells(rowstart, colindex), wsheet.Cells(rowcount, colindex))
Perfect.
Thank you.
Regards,
William
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks