简体   繁体   English

使用VBA获取Excel中动态填充的最后一个单元格值

[英]Use vba to get last cell value in a dynamically populated in excel

I have an excel workbook with 2 sheets 1 & 2. I am running some code to get the Sheet1 populated. 我有一个包含2张纸1和2的excel工作簿。我正在运行一些代码来填充Sheet1。 Now in Sheet2 B1 cell I want the [Sheet1 last cell value in Column D] + 1. 现在在Sheet2 B1单元格中,我想要[Sheet1 D列中的最后一个单元格值] + 1。

Can anyone help me code this. 谁能帮我编码。 Thanks in advance. 提前致谢。

This will capture the last value in column D of Sheet1 这将捕获Sheet1的 D列中的最后一个值

Sub DataCapture()
Dim N As Long, V As Variant
    With Sheets("Sheet1")
        N = .Cells(Rows.Count, "D").End(xlUp).Row
        V = .Cells(N, "D").Value
    End With
    Sheets("Sheet2").Range("B1").Value = V
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM