Vba 尝试删除单元格中的值时出现“参数数目错误或属性分配无效”错误
我的代码段如下:Vba 尝试删除单元格中的值时出现“参数数目错误或属性分配无效”错误,vba,excel,if-statement,invalid-argument,Vba,Excel,If Statement,Invalid Argument,我的代码段如下: If Not Column2 = Empty Then Set Rg2 = sheet.Cells.Find(What:=Column2) If Not Rg2 Is Nothing Then Column2Width = Rg2.MergeArea.Columns.Count - 1 StartCol2Column = Rg2.Column EndCol2Column = StartCol2Column + Co
If Not Column2 = Empty Then
Set Rg2 = sheet.Cells.Find(What:=Column2)
If Not Rg2 Is Nothing Then
Column2Width = Rg2.MergeArea.Columns.Count - 1
StartCol2Column = Rg2.Column
EndCol2Column = StartCol2Column + Column2Width
Else
MsgBox Column2 & " not found in " & BalkanSheet.Name
End If
Else
Worksheets("Graph").Range(Cells(i, 7), Cells(i, 8), Cells(i, 9), Cells(i, 10)).Value = ""
End If
当我尝试运行它时,我在工作表graph.RangeCellsi,7,Cellsi,8,Cellsi,9,Cellsi,10.Value=行中得到一个错误,表示参数数量错误或属性赋值无效
i值是在代码前面设置的变量。我想让代码做的是,如果if语句为false,否则它将删除指定单元格中的值
有什么想法吗?试试这样的方法:
with Worksheets("Graph")
.Range(.Cells(i, 7), .Cells(i, 10)).ClearContents
end with
这个想法是。是一种引用工作表的方法,当您引用单元格时,这是必需的。WorksheetsGraph.RangeCellsi,7,Cellsi,10。ClearContents Range只允许两个参数:开始单元格和结束单元格。这很简单,谢谢!