简体   繁体   中英

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. 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

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.

You are attempting to call a SUB by using it as a child object of a worksheet:

Call Worksheets("WORK").Delete_Blank_Rows

needs to be changed to

Delete_Blank_Rows

Also, remove the Call keyword. You don't need it.

Call Statement (Visual Basic)

You can use the Call keyword when you call a procedure. 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. Use of the Call keyword for other uses isn't recommended .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM