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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.