Needinghlp
New Member
- Joined
- Feb 27, 2013
- Messages
- 25
Hi experts. I have a worksheet (sheet2) that has a list of dates in columns R (start date) and columns S (end date).
Using autofilter, I am trying to identify which rows have dates that are below 1/10/2021 in column R AND column S has a date greater than 30/06/2021. On sheet 2 in cell BD1 I have the date 30/06/2021 and in BE1 I have the date 1/10/2021
I then want to copy the rows (column A to AN) that meet these criteria and paste them to another sheet (sheet1)
Below is my current code... it partially works but it is actually pasting rows with a start date after 1/10/2021 (all the end dates are after 30/06/2021)
The really annoying thing is I fixed this myself last week, but lost my work and now can't remember what I did to fix it... very grateful for any help.
Private Sub CommandButton5_Click()
Dim pDt As Long: pDt = Worksheets("sheet2").[BD1].Value
Dim pDu As Long: pDu = Worksheets("sheet2").[BE1].Value
With Worksheets("sheet2").Range("R3", Worksheets("sheet2").Range("R" & Worksheets("sheet2").Rows.Count).End(xlUp))
.AutoFilter 1, "<" & pDu
With Worksheets("sheet2").Range("S3", Worksheets("sheet2").Range("S" & Worksheets("sheet2").Rows.Count).End(xlUp))
.AutoFilter 1, ">" & pDt
.Offset(1, -18).Resize(, 40).Copy
Worksheets("sheet1").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues
.AutoFilter
End With
End with
End Sub
Using autofilter, I am trying to identify which rows have dates that are below 1/10/2021 in column R AND column S has a date greater than 30/06/2021. On sheet 2 in cell BD1 I have the date 30/06/2021 and in BE1 I have the date 1/10/2021
I then want to copy the rows (column A to AN) that meet these criteria and paste them to another sheet (sheet1)
Below is my current code... it partially works but it is actually pasting rows with a start date after 1/10/2021 (all the end dates are after 30/06/2021)
The really annoying thing is I fixed this myself last week, but lost my work and now can't remember what I did to fix it... very grateful for any help.
Private Sub CommandButton5_Click()
Dim pDt As Long: pDt = Worksheets("sheet2").[BD1].Value
Dim pDu As Long: pDu = Worksheets("sheet2").[BE1].Value
With Worksheets("sheet2").Range("R3", Worksheets("sheet2").Range("R" & Worksheets("sheet2").Rows.Count).End(xlUp))
.AutoFilter 1, "<" & pDu
With Worksheets("sheet2").Range("S3", Worksheets("sheet2").Range("S" & Worksheets("sheet2").Rows.Count).End(xlUp))
.AutoFilter 1, ">" & pDt
.Offset(1, -18).Resize(, 40).Copy
Worksheets("sheet1").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues
.AutoFilter
End With
End with
End Sub