I have a spreadsheet where in column A are peoples names, in column B 3digit codes and in column 3 dates.
In cell B1 is choosen code and in cell C1 is choosen month/year. I want to write a macro which will search for a code from cell B1 within the whole sheet and paste all rows with this code to the new sheet. I have managed to this with this code:
How can I adjust this code so it will not only search for all people with the code mentioned in cell B1 but will only return the rows where there is both the correct B1 code and the date in column C is within the month mentioned in cell C1? In the example below I would only like to get a line "Olaf 307 20/01/2021" as a result.
In cell B1 is choosen code and in cell C1 is choosen month/year. I want to write a macro which will search for a code from cell B1 within the whole sheet and paste all rows with this code to the new sheet. I have managed to this with this code:
VBA Code:
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
j = 2
For Each c In Source.Range("B1:B30000")
If c = Range("$B$1").Value Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub