MishTaylor
New Member
- Joined
- May 4, 2021
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
Hi Everyone,
I need some help with my code to reference the table properly. Right now, when I run this code, the data populates outside of the table - not sure how to reference the table correctly.
Table = "PrevReport"
Sheet = "Print Reports"
The data is being filtered by date range from another sheet called "Packaged&Restock"
Thanks!
I need some help with my code to reference the table properly. Right now, when I run this code, the data populates outside of the table - not sure how to reference the table correctly.
Table = "PrevReport"
Sheet = "Print Reports"
The data is being filtered by date range from another sheet called "Packaged&Restock"
Thanks!
VBA Code:
Private Sub PreviewBtn_Click()
Dim i As Long
Dim startdate As Date
Dim enddate As Date
Dim ws As Worksheet
Set RTAB = ws.ListObjects("PrevReport")
Set REP = ThisWorkbook.Sheets("PrintReports")
Set TOT = ThisWorkbook.Sheets("Packaged&Restock")
Application.ScreenUpdating = False
startdate = REP.Range("H2").Value
enddate = REP.Range("I2").Value
RTAB.Range("A" & 11, "I" & 100000).ClearContents
For i = 2 To TOT.Range("A100000").End(xlUp).Row
If TOT.Cells(i, 1) >= startdate And _
TOT.Cells(i, 1) <= enddate Then
RTAB.Range("A100000").End(xlUp).Offset(1, 0) = TOT.Cells(i, 1)
For x = 1 To 10
RTAB.Range("A100000").End(xlUp).Offset(0, x) = TOT.Cells(i, x + 1)
Next x
End If
Next i
End Sub