I need that when i run this code every time data should be pasted to next row. Salary sheet is raw data file , and final slaary is final sheet where data is to be copied. Please help
Sub TestThat()
'Declare the variables
Dim DataSh As Worksheet
Dim finalSh As Worksheet
Dim monthsRange As Range
Dim rCell As Range
Dim i As Long
'Set the variables
Set DataSh = ThisWorkbook.Sheets("Salary Sheet")
Set finalSh = ThisWorkbook.Sheets("Final Salary")
Set monthsRange = DataSh.Range(DataSh.Cells(3, 1), DataSh.Cells(Rows.Count, 1).End(xlUp))
'I went from the cell row3/column1 (or a3) and go down until the last non empty cell
i = 2
For Each rCell In monthsRange 'loop through each cell in the range
If rCell = Sheets("Menu").Range("E6").Value Then 'check if the cell is equal to "range e6"
i = i + 1 'Row number (+1 everytime I found another "range e6")
finalSh.Cells(i, 1) = rCell.Offset(0, 0) 'month
finalSh.Cells(i, 2) = rCell.Offset(0, 1) 'emp id
finalSh.Cells(i, 3) = rCell.Offset(0, 2) 'emp name
finalSh.Cells(i, 4) = rCell.Offset(0, 3) 'designation
finalSh.Cells(i, 5) = rCell.Offset(0, 22) 'gross salary
End If
Next rCell
End Sub