Hi All,
I am having difficulty understanding why the following code won't work. I get a "Compile error: Method or data member not found" on .InputRng.
Here is the code:
Sub Test()
Dim LastRow As Long
Dim InputSht As Worksheet
Dim InputRng As Range
Dim bar_mark As String
LastRow = Range("A7").End(xlDown).Row
Set InputSht = Worksheets("Input")
Set InputRng = Range("A7:M" & LastRow)
For r = 1 To 350
bar_mark = InputSht.InputRng.Cells(r + 1, 2)
Next r
End Sub
For some reason that I can't understand the following code does work (where I do not set a variable to the range object):
Sub Test()
Dim LastRow As Long
Dim InputSht As Worksheet
Dim bar_mark As String
LastRow = Range("A7").End(xlDown).Row
Set InputSht = Worksheets("Input")
For r = 1 To 350
bar_mark = InputSht.Range("A7:M" & LastRow).Cells(r + 1, 2)
Next r
End Sub
The sub also runs with the following code:
Sub Test()
Dim LastRow As Long
Dim InputRng As Range
Dim bar_mark As String
LastRow = Range("A7").End(xlDown).Row
Set InputRng = Worksheets("Input").Range("A7:M" & LastRow)
For r = 1 To 350
bar_mark = InputRng.Cells(r + 1, 2)
'which is the same as
'bar_mark = Worksheets("Input").Range("A7:M" & LastRow).Cells(r + 1, 2)
Next r
End Sub
I just can't figure out why the syntax for the fist sub gives the error.
I am still learning the ins and outs of VBA so please assist. Many thanks.
Bookmarks