Forum Discussion
heathermarie923
Sep 14, 2022Copper Contributor
Copy multiple scattered rows from Sheet 1 to Sheet 2 at one time
Okay forum. One more post, I'm sorry. So, my end goal is to have an automated spreadsheet that every time you open it it automatically looks at column E in Sheet 1 (List of UPCs) and if the date...
- Sep 14, 2022
Try this version:
Private Sub Workbook_Open() 'Declaring variables Dim ws As Worksheet Dim wt As Worksheet Dim i As Long Dim Lastrow As Long Dim NewRecordsRow As Long Application.ScreenUpdating = False Set ws = Worksheets("List of UPCs") Set wt = Worksheets("Historical Data") Lastrow = ws.Range("B" & ws.Rows.Count).End(xlUp).Row NewRecordsRow = wt.Range("B" & wt.Rows.Count).End(xlUp).Row For i = 2 To Lastrow If ws.Cells(i, "E").Value < Date Then NewRecordsRow = NewRecordsRow + 1 ws.Cells(i, "E").EntireRow.Copy Destination:=wt.Cells(NewRecordsRow, 1) ws.Range(ws.Cells(i, 3), ws.Cells(i, 5)).Clear End If Next i Application.ScreenUpdating = True MsgBox "Fill in any blank Column E fields with the formula =today(). This ensures certain functions act accordingly." End Sub
HansVogelaar
Sep 14, 2022MVP
Try this version:
Private Sub Workbook_Open()
'Declaring variables
Dim ws As Worksheet
Dim wt As Worksheet
Dim i As Long
Dim Lastrow As Long
Dim NewRecordsRow As Long
Application.ScreenUpdating = False
Set ws = Worksheets("List of UPCs")
Set wt = Worksheets("Historical Data")
Lastrow = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
NewRecordsRow = wt.Range("B" & wt.Rows.Count).End(xlUp).Row
For i = 2 To Lastrow
If ws.Cells(i, "E").Value < Date Then
NewRecordsRow = NewRecordsRow + 1
ws.Cells(i, "E").EntireRow.Copy Destination:=wt.Cells(NewRecordsRow, 1)
ws.Range(ws.Cells(i, 3), ws.Cells(i, 5)).Clear
End If
Next i
Application.ScreenUpdating = True
MsgBox "Fill in any blank Column E fields with the formula =today(). This ensures certain functions act accordingly."
End Sub
- heathermarie923Sep 14, 2022Copper ContributorI pray to the VBA Gods good fortune for you lol
It works great!