中插入值,當我得到運行時錯誤「1004」Excel的VBA - 錯誤「1004」的最後一個非空行
應用程序定義或對象定義的錯誤
當我」 m嘗試從B19開始插入值。
下面是代碼:
Private Sub test()
If Application.CountIf(Sheets("Sheet1").Columns(2), Range("A5").Value) Then
MsgBox "Already taken, try another username"
Else
MsgBox "Done"
Sheets("Sheet1").Range("B19" & Rows.Count).End(xlUp).Offset(1, 0) = Range("A5").Value
End If
End Sub
這段代碼的目的是從A5插入值到最後一個非空行從B19開始。
您的地址:'( 「B19」 和Rows.Count)'解析爲'B191048576',這是一個非法地址。因此錯誤。 B列中的最後一個空單元格將由'cells(rows.Count,「B」)返回。end(xlup).offset(1,0)'**但是**您必須專門測試'B19'不是空的,如果你想從'B19'開始 –