[英]Using VBA, I want to count the number of rows and then print this in a specific cell
Here's the code I'm using but it's not working这是我正在使用的代码,但它不起作用
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
Essentially, I want it to count the rows and then print the value in Q1.本质上,我希望它计算行数,然后在 Q1 中打印值。
Thanks in advance.提前致谢。
Try this:尝试这个:
Sub CountRowsAndPrintInColumnQ()
Dim Index As Long
Index = 1
Do Until Range("A" & Index).Value = ""
Index = Index + 1
Loop
Range("Q1").Value = Index
End Sub
also an option也是一种选择
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.