I am very new to the VBA space, and am wondering why doesn't this following line of code work?
I am getting error 1004: Range of object worksheet failed
Sub MMMatch()
Dim oCell as Range
Dim r_out as Range
Dim r_in as Range
Dim ws1 as worksheet
Dim ws2 as worksheet
Set ws1 = Worksheets("MM Limits")
Set ws2= Worksheets("PivotTable")
Set r_out= ws1.range(Range("A2"),Range("A2").endxldown)
Set r_in=ws2.range(range("D2"),range("D2").endxldown)
end sub
I am getting the error on the 2nd last line. While I could add in the lines of code to select the worksheet first before setting the range object, I am wondering why wouldn't this line of code work?