我的片材的樣子:
如何在VBA中找到第一個空單元格?
我有一個函數來獲取LAST空單元的索引在列A:
NextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
此功能對第二陣列寫(類型2) 。
但現在,我想一個函數來獲取A列FIRST空單元格的指數讓我去這個網站: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
?
'xlDown'可能會誤導它,因爲它發現某個區域中的最後一個單元格 - 所以如果A2是空白的但使用了A3,則它不會到達A3。相反,如果範圍爲空,它將跳轉到工作表上的最後一行。 – brettdj