add restrict to code when reach in specific lastrow and move to next sheet

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi

I have this code copy data from sheet to another what I want after copy data to sheet 2 when reach to last row is 1000 it moves automatically to next sheet is sheet3 and start the data from row 2 as in sheet2 .the same thing when the data reaches in sheet3 in lastrow 1000 then should move to next sheet4 and so on
the restrict depends on lastrow(1000) . the data begins from A1: D as in my code .

VBA Code:
Sub CopyData()

Dim LastRow As Long, d As Long
Dim CopyRange As Range, count As Long

With Sheets("sheet1")
   LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
  
   For d = LastRow To 10 Step -1
  
   If .Cells(d, "A") = Date - 1 Or .Cells(d, "A").Value = Date Then
      count = count + 1
         If CopyRange Is Nothing Then
                   Set CopyRange = .Rows(d).EntireRow
           Else
                   Set CopyRange = Union(CopyRange, .Rows(d).EntireRow)
           End If
       End If
   Next d
End With
   CopyRange.Copy Sheets("sheet2").Range("A3")
End Sub

I hope my thread is logic .
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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