Reputation: 409
I am getting a runtime error, 1004 when I run the below code in vba
MsgBox Workbooks(SourceFile1).Worksheets(WS).Range(Cells(ThisRow, ThisColumn), Cells(ThisRow, ThisColumn)).Interior.Color
but don't get any error in the following code:
MsgBox Workbooks(DestinationFile).Sheets(1).Range(Cells(I, 14), Cells(I, 14)).Interior.Color
The SourceFile1 opens up as I coded it do so. Also ThisRow shows a value of 9 and ThisColumn shows as 11 in debug mode
Is there a solution to this?
Thanks
Upvotes: 0
Views: 699
Reputation: 34055
Assuming your variables are appropriate, your Cells calls are not properly qualified with a worksheet - you need:
With Workbooks(SourceFile1).Worksheets(WS)
MsgBox .Range(.Cells(ThisRow, ThisColumn), .Cells(ThisRow, ThisColumn)).Interior.Color
End With
or in this case, since you are looking at one cell only:
Msgbox Workbooks(SourceFile1).Worksheets(WS).Cells(ThisRow, ThisColumn).Interior.Color
Upvotes: 1