[英]Excel Macro For Data Analysis
I'm building a spreadsheet macro that copies cells from one spreadsheet called DATA to a tab called REPORT based on criteria. 我正在构建一个电子表格宏,该宏可以根据条件将单元格从一个名为DATA的电子表格复制到一个名为REPORT的选项卡。 If the criteria changes, the list clears and it adds the values that meet the new criteria. 如果条件更改,该列表将清除,并添加符合新条件的值。 The macro is: 宏是:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("B2:C5")
If Not Application.Intersect(KeyCells, Target) _
Is Nothing Then
For iRow = 2 To 5845
If Worksheets("DATA").Range("F" & iRow).Value = False Then
'Do nothing
Else
Worksheets("WORK").Cells(iRow, 1).Value = Worksheets("DATA").Cells(iRow, 4).Value
End If
Next iRow
End If
Call Worksheets("WORK").Delete_Blank_Rows
Sheets("REPORT").Range("E1:E5845").Value = Sheets("WORK").Range("A1:A5845").Value
Worksheets("REPORT").Columns(6).ClearContents
End Sub
Sub Delete_Blank_Rows()
On Error Resume Next
With Worksheets("WORK").Range("A2:A5845")
.Value = .Value
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub
The spreadsheet is here: https://drive.google.com/file/d/1G-RQ9DvGKa_EEapcLIWDf3_SCdql_dJJ/view?usp=sharing 电子表格位于此处: https : //drive.google.com/file/d/1G-RQ9DvGKa_EEapcLIWDf3_SCdql_dJJ/view?usp=sharing
The error I receive is 我收到的错误是
runtime error saying object doesn't support property or method. 运行时错误,指出对象不支持属性或方法。
Any help is appreciated! 任何帮助表示赞赏!
Your Call
method of your worksheet object appears to be causing the issue. 您的工作表对象的Call
方法似乎是引起此问题的原因。
You are attempting to call a SUB by using it as a child object of a worksheet: 您试图通过将SUB用作工作表的子对象来调用它:
Call Worksheets("WORK").Delete_Blank_Rows
needs to be changed to 需要更改为
Delete_Blank_Rows
Also, remove the Call
keyword. 另外,删除Call
关键字。 You don't need it. 不用了
Call Statement (Visual Basic) 通话说明(Visual Basic)
You can use the
Call
keyword when you call a procedure. 调用过程时,可以使用Call
关键字。 For most procedure calls, you aren't required to use this keyword. 对于大多数过程调用,不需要使用此关键字。You typically use the
Call
keyword when the called expression doesn't start with an identifier. 当被调用的表达式不是以标识符开头时,通常使用Call
关键字。 Use of theCall
keyword for other uses isn't recommended . 不建议将Call
关键字用于其他用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.