![](/img/trans.png)
[英]VBA Excel ComboBox value to Range ("specific cell" to last column with data)
[英]Check which is the last cell in a specific column which has a value and select the cell below it in excel vba
您好,我正在尝试编写一些代码来获取特定列(例如A列)中具有值的最后一个单元格。 我只知道这一点:
Cells(3, 2).Value = quantity
要确定最后一行,请使用以下公式
lastRow = Cells(rows.count,1).End(xlUp).row
您可以在此命令中搜索更多内容。
现在,一旦知道了最后一行,就可以使用它来获取其值
Variable = Cells(lastRow,1).Value
如果要查找范围中最后一个单元格的行,最好使用find函数。
例如:对于特定列n; 使用下面的代码将其设置为数量
Dim n As Long, quantity As Long
n = 3
quantity = 5000
Cells(Columns(n).Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, _
SearchDirection:=xlPrevious).Row, n).Value = quantity
像这样的东西检查:
码
Sub LastRow()
Dim rng1 As Range
Set rng1 = Columns("A").Find("*", [a1], xlValues, , xlByRows, xlPrevious)
If Not rng1 Is Nothing Then
If rng1.Row <> Rows.Count Then rng1.Offset(1, 0).Activate
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.