I am new to Excel and VBA programming, I have made attendance sheet and want to copy data from one sheet to other ( month wise) by pressing button.
I am getting error at the following line
lastrow1 = Sheets(“Sheet14”).Range(“A” & Rows.Count).End(xlUp).Row
My code
Sub Button2_Click()
Dim i As Long, j As Long, lastrow1 As Long, lastrow2 As Long
Dim myname As String
lastrow1 = Sheets(“Sheet14”).Range(“A” & Rows.Count).End(xlUp).Row
For i = 7 To lastrow1
myname = Sheets(“Sheet14”).Cells(i, “A”).Value
Sheets(“sheet2”).Activate
lastrow2 = Sheets(“sheet2”).Range(“A” & Rows.Count).End(xlUp).Row
For j = 7 To lastrow2
If Sheets(“sheet2”).Cells(j, “A”).Value = myname Then
Sheets(“Sheet14”).Activate
Sheets(“Sheet14”).Range(Cells(i, “D”), Cells(i, “AH”)).Copy
Sheets(“sheet2”).Activate
Sheets(“sheet2”).Range(Cells(j, “D”), Cells(j, “AH”)).Select
ActiveSheet.Paste
End If
Next j
Application.CutCopyMode = False
Next i
Sheets(“Sheet14”).Activate
Sheets(“Sheet14”).Range(“D7”).Select
End Sub