Limit to the number of rows Excel VBA will select/copy

jw116

New Member
Joined
Mar 25, 2013
Messages
1
I'm trying to make a macro that will select the even number of rows and paste into a new workbook.
-------------------------------------------
Here is my code:


Sub rows()
Dim s, collection As String
collection = "2:2"
endrow = 44
'errors when I put anything above 44

For x = 2 To endrow
s = 2 * x & ":" & 2 * x
collection = collection & "," & s
Range(collection).Copy
Next x

End Sub

------------------------


The code stops working when I change endrow from 44 to 45. There appears to be a limit to the number of rows Excel VBA wants to copy or select. The only other way I can think of is making a loop that selects one row and immediately pastes it into the new workbook and repeats. Is there any other way that it can select all the rows that fit the criteria and pastes it over in one block?



Any help would be appreciated!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this.
Code:
Sub CopyEvenRows()
Dim s As Long
Dim endrow As Long
Dim x As Long

Dim collection As Range

    Set collection = Range("2:2")
    endrow = 45
    'errors when I put anything above 44

    For x = 2 To endrow

        s = 2 * x & ":" & 2 * x

        Set collection = Union(collection, Range(s))

    Next x
    
    collection.Copy
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,196,385
Messages
6,014,974
Members
441,860
Latest member
Store154

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