I want to have my program begin a count at a specific location defined by a variable. I know that you can use rn = sh.Cells(9, 1) for example, and the variable rn is now holding the location of cells(9,1). But when I use the variable rn in my count command, I am getting the following error:
Method 'Range' of object' _worksheet' failed
Here's my code:
Option Explicit
Sub Struc_Equa()
Dim n As Integer
End sub
Sub countN(n)
Dim sh As Worksheet
Dim rn As Range
Dim SheNa As String
SheNa = ActiveSheet.Name
Set sh = ThisWorkbook.Sheets(SheNa)
Set rn = sh.Cells(9, 1)
' The command below does not work
'n = sh.Range(rn, sh.Range(rn).End(xlToRight)).Columns.Count
' I am able to do what I want but in a inefficient way (shown below)
'n = sh.Range("A9", sh.Range("A9").End(xlToRight)).Columns.Count
rn.Activate
MsgBox (n)
End Sub
Why is this error happening?