excel - 如何在 VBA 中找到第一个空单元格?

标签 excel vba

我的工作表看起来像:
enter image description here

我有一个函数来获取 的索引最后 A列中的空单元格:

NextRow = Range("A" & Rows.Count).End(xlUp).Row + 1

此函数可用于写入第二个数组(Type2)。

但是现在,我想要一个函数来获取 的索引第一 A列中的空单元格。所以我去了这个网站:Select first empty cell我试图调整代码,但它不起作用:
If Array= "Type1" Then
    Dim ws As Worksheet
    Set ws = ActiveSheet
    For Each cell In ws.Columns(1).Cells
       If IsEmpty(cell) = True Then NextRow = cell: Exit For 'ERROR 1004
    Next cell
End If
If Array= "Type2" Then 'It s works
    NextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
End If

ActiveSheet.Range("A" & NextRow) = "TEST"

你能帮我修改我的代码以拥有NextRow = IndexOf FIRST empty cell in A吗? ?

最佳答案

您可以使用与获取最后一个相同的方法。

NextRow = Range("A1").End(xlDown).Row + 1

关于excel - 如何在 VBA 中找到第一个空单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40301822/

相关文章:

c# - Excel Interop (Visual Studio C#) - "Embed Interop Type"属性

vba - 用于合并数据的 Excel 宏

vba - 应用程序定义或对象定义的错误 Ubound

excel - 打印时出错

excel - 无法通过使用公式生成 X 坐标和 Y 坐标

python - 使用 Python 在 Excel 中插入指向本地文件夹的超链接

excel - 如何从Excel文件中读取单元格值

vba - Excel 和 VBA : Skip calculating formula in Macro

vba - 如果路径中不存在附件文件,则不应发送邮件

excel - VBA - 网页抓取无法获取 HTMLElement insideText