首页 文章

使用范围中的数据填充最后一列

提问于
浏览
0

我知道我们可以使用以下代码获取包含数据的最后一行:

LastRow = .Range(“D”&.Rows.Count).End(xlUp).Row

但是我在使用数据获取最后一列时遇到了麻烦 . 这是我尝试过的,你可以从它没有经过的图像中看到

Set ws = ThisWorkbook.ActiveSheet
With ws 
 Header = 5
 LastRow = .Range("D" & .Rows.Count).End(xlUp).Row
 LastCol = .Range(5 & .ColumnCount).End(xlLeft).Column
    With .Range("A" & Header & LastCol & LastRow)
         .Interior.ColorIndex = 16
    End With
End With

enter image description here

能告诉我锄头我可以解决这个问题吗?谢谢

1 回答

  • 2

    试试这个,因为我已经评论过:

    Lastcol = .Cells(5, Columns.Count).End(xlToLeft).Column
    

    我不确定它是 xlLeft 还是 xlToLeft . 亲自尝试一下 .

    使用它来为整个范围着色:

    With .Range(Cells(1,5),Cells(Lastrow,Lastcol)
        .Interior.ColorIndex = 16
    End With
    

    这个颜色 A5 到你的最后一列和一行 .

相关问题