本文介绍了查找范围内充满数据的最后一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我们可以使用以下代码获取包含数据的最后一行:
I know we can get the last row with data with following code:
但是我在获取带有数据的最后一列时遇到了麻烦.这是我尝试过bu的结果,您可以从没有经历的图像中看到
But I am having trouble on getting the last Column with data. Here is what i tried bu as you can see from the image it didn't go through
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
您能告诉我我可以解决这个问题吗?谢谢
Can you please let me know hoe I can fix this? thanks
推荐答案
在我评论过后尝试以下方法:
Try this as i've commented:
Lastcol = .Cells(5, Columns.Count).End(xlToLeft).Column
我不确定是xlLeft
还是xlToLeft
.自己尝试.
i'm not sure if its xlLeft
or xlToLeft
. Try it yourself.
使用它为整个范围着色:
Use this to color the entire range:
With .Range(Cells(1,5),Cells(Lastrow,Lastcol)
.Interior.ColorIndex = 16
End With
这会将A5
颜色变为最后一列和另一行.
this colors A5
to your last column and row.
这篇关于查找范围内充满数据的最后一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!