0
votes

I am very new to VBA coding and tried to find the code for a specific task. I have a database ("Sanitation") with a date column. The database is on the sheet "Sanitation Schedule". I have created a form to set the required start and end dates and copy them on cell A2 (start date) and A3 (end date) of sheet "Sanitation Form". I want to select the rows of my database between the predetermined start and end dates, copy the rows to an other sheet "Sanitation Form". It sounds probably very basic coding but it is out of my knowledge. Thank you for your help.

1

1 Answers

0
votes

You can use .Find

Dim StartDate As Date
StartDate = ThisWorkbook.Worksheets("Sanitation Form").Range("A2").value
Dim EndDate As Date
EndDate = ThisWorkbook.Worksheets("Sanitation Form").Range("A3").value

Startrow = ThisWorkbook.Worksheets("Sanitation").Cells.Find(Format(StartDate, "d-mmm-yy"), ThisWorkbook.Worksheets("Sanitation").Range("A1"), xlValues, xlPart, xlByColumns, xlNext, False, False).Row
Endrow = ThisWorkbook.Worksheets("Sanitation").Cells.Find(Format(EndDate, "d-mmm-yy"), ThisWorkbook.Worksheets("Sanitation").Range("A1"), xlValues, xlPart, xlByColumns, xlNext, False, False).Row

And then copy the rows in between