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