Vba Excel代码选择列,即使有空单元格
您好,我目前正在使用此代码,但它只选择列,直到找到一个空单元格,我想要的是从H3单元格选择列,直到该列中的最后一个值,即使有空行Vba Excel代码选择列,即使有空单元格,vba,excel,select,Vba,Excel,Select,您好,我目前正在使用此代码,但它只选择列,直到找到一个空单元格,我想要的是从H3单元格选择列,直到该列中的最后一个值,即使有空行 Range("H3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select 也就是说。尽量不要使用选择。为什么要选择范围?简单点。首先,声明一个变量,它可以保存您感兴趣的列中使用的最后一行,并声明一个变量来保存范围并
Range("H3").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
也就是说。尽量不要使用
选择。为什么要选择范围?简单点。首先,声明一个变量,它可以保存您感兴趣的列中使用的最后一行,并声明一个变量来保存范围并进行设置。从长远来看,这将对你有所帮助
e、 看下面的代码
Sub Test()
Dim LastRow As Long
Dim Rng As Range
'This will find the last row used in column H
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
'Set the Rng variable
Set Rng = Range("H3:H" & LastRow)
'Now do whatever you like to do with this range, like
Rng.Select
MsgBox Rng.Address
Rng.Interior.Color = vbYellow
'etc
'If you want to perform multiple actions on the same range, you can also use With and End With block like below
With Rng
.Value = "Test"
.Font.Size = 14
.Font.Bold = True
.HorizontalAlignment = xlCenter
.RowHeight = 25
'etc
End With
End Sub
看到这一点,你的链接给我一个想法,首先替换空白值,然后选择所有column@subodh_tiwari_sktneer您是否可以执行类似的操作来查找最后一列,然后将这两个列放在一起动态查找最后一行和最后一列?
Sub Test()
Dim LastRow As Long
Dim Rng As Range
'This will find the last row used in column H
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
'Set the Rng variable
Set Rng = Range("H3:H" & LastRow)
'Now do whatever you like to do with this range, like
Rng.Select
MsgBox Rng.Address
Rng.Interior.Color = vbYellow
'etc
'If you want to perform multiple actions on the same range, you can also use With and End With block like below
With Rng
.Value = "Test"
.Font.Size = 14
.Font.Bold = True
.HorizontalAlignment = xlCenter
.RowHeight = 25
'etc
End With
End Sub