![](/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.