excel:填充单元格时运行时错误424
我只写了一个简单的代码,在一个名为BASE_TOTAL
的表单上从一个列的开始到结尾运行(例如,第11列),每次find一个空单元格时,都会在其上写入“Sem Substituto”。
这是我迄今为止所尝试的:
Sub FillSubs() Dim i As Long Dim Lastrow As Long Dim ws1 As Worksheet Set ws1 = Sheets("BASE_TOTAL") Set Lastrow = ws1.Range("A" & rows.Count).End(xlUp).Row For i = 1 To Lastrow If ws1.Cells(i, 11).Value = "" Then ws1.Cells(i, 11).Value = "Sem Substituto" End If Next i End Sub
但是当我尝试运行这个代码时,它给了我:
运行时错误“424”对象需要
并强调这一部分:
Sub FillSubs()
虽然我不知道我的variables有什么问题,因为我真的认为我宣称他们是正确的。
我感谢任何帮助。
你不应该“设置”拉斯特罗
更正了以下代码
Sub FillSubs() Dim i As Long Dim Lastrow As Long Dim ws1 As Worksheet Set ws1 = Sheets("BASE_TOTAL") Lastrow = ws1.Range("A" & rows.Count).End(xlUp).Row For i = 1 To Lastrow If ws1.Cells(i, 11).Value = "" Then ws1.Cells(i, 11).Value = "Sem Substituto" End If Next i End Sub
你的variablesLastrow是一个很长的,因此你不需要使用Set。 只要这样做:
Lastrow = ws1.Range("A" & rows.Count).End(xlUp).Row