0

I'm new to the coding and have written the following code to fetch particular data from selected cells after checking a few conditions and putting it into another Excel sheet. It is throwing an

compile error with message object required.

The code is:

Sub test()
    Dim LastRow As Integer, i As Integer, erow As Integer, a As Integer, b As 
    Integer

    LastRow = ActiveSheet.Range(“A” & Rows.Count).End(xlUp).Row

    For i = 3 To LastRow
        If Cells(i, 3) = "Grade" And Cells(i, 4) <> Null Then
            Set a = ActiveSheet.Cells(i, 3)
            Set b = ActiveSheet.Cells(i, 7)
            Union(a, b).Select

            Selection.Copy

            Workbooks.Open Filename:="C:\Users\413302\Desktop\Test.xlsx"

            Worksheets(“Sheet1”).Select
            erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

            ActiveSheet.Cells(erow, 1).Select
            ActiveSheet.Paste
            ActiveWorkbook.Save
            ActiveWorkbook.Close
            Application.CutCopyMode = False
        End If
    Next i
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • You might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). • Also these fancy quotes you use for strings `“ ”` are not allowed and need to be replaced with the regular ones `" "`. • If you get errors always tell in which line you get them. • Your row counting variables should all be `Long` instead of `Integer` because Excel has more rows than fit into `Integer`. – Pᴇʜ Jul 16 '19 at 14:00
  • You can't compare a cell to Null. The answer will be `Null`, not `True` or `False`. To see if a cell is blank compare it to `""`. –  Jul 16 '19 at 14:11

0 Answers0