![](/img/trans.png)
[英]how to count the number of rows with data from a specific cell in excel vba
[英]Using VBA, I want to count the number of rows and then print this in a specific cell
這是我正在使用的代碼,但它不起作用
Sub CountRowsAndPrintInColumnQ()
Dim last_row As Long
Dim Result As Long
Set last_row = Cells(Rows.Count, 1).End(xlUp).Row
Set Result = Range("Q1")
Result.Value = last_row
End Sub
本質上,我希望它計算行數,然后在 Q1 中打印值。
提前致謝。
嘗試這個:
Sub CountRowsAndPrintInColumnQ()
Dim Index As Long
Index = 1
Do Until Range("A" & Index).Value = ""
Index = Index + 1
Loop
Range("Q1").Value = Index
End Sub
也是一種選擇
Sub CountRowsAndPrintInColumnQ()
'This will write column "A" number of rows into cell Q1
ActiveSheet.Range("Q1").Value = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.