Copy and Paste Rows Until Condition is Met

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I have this code in the "This Workbook" section. It functions well, but not perfectly. I'd like for it to continue the copy and paste routine until the value in column BZ, in the LastRow, = "Current". For some reason, it only pastes 2 or 3 rows at a time. What change do I need to make to the code, to get the desired result?

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)'Copies the last row, if the Pymt Stats = Paid or Late, and pastes it to the row below.
Application.ScreenUpdating = False


Dim ws As Worksheet
Dim LastRow As Long


For Each ws In Worksheets
    If Not ws.Name = "Displays" And Not ws.Name = "Management" And Not ws.Name = "Summaries" And Not ws.Name = "Bios" And Not ws.Name = "Stats" _
    And Not ws.Name = "Appt Tracker" And Not ws.Name = "Pymt Tracker" And Not ws.Name = "Financials" And Not ws.Name = "Variables" Then
        LastRow = ws.Range("BZ" & ws.Rows.Count).End(xlUp).Row
        If ws.Range("BZ" & LastRow).Value = "Paid" Or ws.Range("BZ" & LastRow).Value = "Late" Then
            ws.Range("A" & LastRow + 1) = "=Today()"
            ws.Range("B" & LastRow + 1) = Now()
            ws.Range("C" & LastRow + 1) = "Update"
            ws.Range("D" & LastRow & ":U" & LastRow).Copy ws.Range("D" & LastRow + 1)
            ws.Range("W" & LastRow & ":AF" & LastRow).Copy ws.Range("W" & LastRow + 1)
            ws.Range("AG" & LastRow & ":AO" & LastRow).Copy ws.Range("AG" & LastRow + 1)
            ws.Range("AQ" & LastRow & ":AY" & LastRow).Copy ws.Range("AQ" & LastRow + 1)
            ws.Range("BA" & LastRow & ":BI" & LastRow).Copy ws.Range("BA" & LastRow + 1)
            ws.Range("BK" & LastRow & ":BZ" & LastRow).Copy ws.Range("BK" & LastRow + 1)
            ws.Range("BR" & LastRow + 1).Value = 0
            ws.Range("BS" & LastRow + 1).Value = 0
            ws.Range("BT" & LastRow + 1).Value = 0
            ws.Range("BU" & LastRow + 1).Value = 0
            ws.Range("BV" & LastRow + 1).Value = 0
        End If
    End If
Next ws
Application.Calculation = xlCalculationAutomatic
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top