简体   繁体   中英

Highlight Column VBA EXCEL Starting at Second Column

I'm trying to highlight a column starting from row 2 this is my code below

Dim Lastrow As Integer
Lastrow = Sheets("OPEN - REPEAT").Cells(Rows.Count, 1).End(xlUp).Row
Workbooks(var2).Sheets("OPEN - REPEAT").Columns("A2" & Lastrow).Interior.Color = vbYellow

I keep getting the following error Application or Object Defined error 1004 any idea what I might be doing wrong?

.Columns("A2" & Lastrow) is all wrong. Use .Range and you also need to specify an end column and end row, so it should look like this:

Workbooks(var2).Sheets("OPEN - REPEAT").Range("A2:A" & Lastrow).Interior.Color = vbYellow

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM