Good afternoon,
I have researched this for days, but cannot get my code to work, and I am wondering what specifically is wrong. Here is the code:
The code runs, and I can see it pulling the data (and it is the correct data), but it is overwriting cell I1 instead of putting the first selection in I1, the next data in I2, etc. I have tried to do this multiple ways, but when I add .Offset(1,0) or .Offset(1) to the end of where I have defined LastRow, my code gives me an error.
What I am trying to accomplish is to pull the daily error data from the prior day. The macro is designed to loop through the table with all the data, and see if 1) It matches the date for prior day (In cell K1 I have a formula to figure prior day) and 2) If there are errors (column 40 is a Yes/No check if there are errors).
I have tried several ways, but still cannot get this to work; the above code has been my best attempt. Any help is greatly appreciated, as I am new to VBA!
Thank you!
I have researched this for days, but cannot get my code to work, and I am wondering what specifically is wrong. Here is the code:
Code:
Sub DailyErrors1()
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("owssvr")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Daily Dashboard")
Dim tbl As ListObject
Dim i As Long
Dim LastRow As Variant
Set tbl = ws1.ListObjects("Table_owssvr")
LastRow = ws2.Cells(Rows.Count, "I").End(xlUp).Row
MyDate = ws2.Range("K1").Value
For i = 2 To tbl.Range.Rows.Count
If ws1.Cells(i, 98).Value = MyDate And ws1.Cells(i, 40).Value = "Yes" Then
ws2.Range("I" & LastRow).Value = ws1.Cells(i, 42).Value
End If
Next i
End Sub
The code runs, and I can see it pulling the data (and it is the correct data), but it is overwriting cell I1 instead of putting the first selection in I1, the next data in I2, etc. I have tried to do this multiple ways, but when I add .Offset(1,0) or .Offset(1) to the end of where I have defined LastRow, my code gives me an error.
What I am trying to accomplish is to pull the daily error data from the prior day. The macro is designed to loop through the table with all the data, and see if 1) It matches the date for prior day (In cell K1 I have a formula to figure prior day) and 2) If there are errors (column 40 is a Yes/No check if there are errors).
I have tried several ways, but still cannot get this to work; the above code has been my best attempt. Any help is greatly appreciated, as I am new to VBA!
Thank you!