I am new to VBA and I am not sure how I can accomplish the following task.
I want to ask the user for a date range and then take that date range and search through column BB of “Source Sheet” for any date in that range. If a date is in that range I want to take the entire row and copy it and then paste it into a different sheet called “Dest Sheet”
Any help is appreciated! I have tried many different ways of doing this and nothing I have done is working. Here is what I currently have
Dim N As Integer
Dim i As Integer
Dim StartDate As Date
Dim EndDate As Date
N = Cells(Rows.Count, "E").End(xlUp).Row 'determines the last row with data in it
'uses column E because E should never be Null if not after last active row
Dim j As Integer 'declares j for indexing of the rows on the target spreadsheet
j = 2
Dim fRow As Long 'is the role of j in an attempt to copy and paste
fRow = Sheets("Dest Sheet").UsedRange.Rows.Count 'defines the variable
For i = 2 To N 'indexes 2 to N to begin with row after the title row to the last active ro
Cells(i, "BB").Select
If Cells(i, "BB").Value <> "" Then
Columns("BB").Select
Selection.NumberFormat = "mm/dd/yyyy"
Range("BB2").End(xlDown).Select
StartDate = Application.InputBox("Enter the start date")
EndDate = Application.InputBox("Enter the end date")
'in row i execute the if statement
If ("BB" >= StartDate & "BB" <= EndDate) Then
Sheets("Source Sheet").Cells(i, 1).EntireRow.Copy Destination:=Sheets("Dest Sheet").Cells(fRow, 1).Offset(1, 0)
fRow = fRow + 1
End If
End If 'declares end of the if statements
Next i
End Sub