Finding last row of column not recognizing all rows in column

uvela

New Member
Joined
Feb 18, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hello,

I've created a workbook with 4 worksheets that have been copied from other workbooks. In this workbook I'm trying to copy and paste all data from a column in sheet1 to sheet2.

I'm using the following vba code:

VBA Code:
Dim lastRow As Long
    
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    Sheets("sheet1").Activate
    Range("A2:A" & lastRow).Copy
    Sheets("sheet2").Activate
    Range("A2").PasteSpecial Paste:=xlPasteValues

In my case, sheet1 has 63863 rows, but the above code only pastes 32582 rows into sheet2.

Any suggestions or help would be greatly appreciated.

Thanks:)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
VBA Code:
Dim lastRow As Long

    Sheets("sheet1").Activate
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A2:A" & lastRow).Copy
    Sheets("sheet2").Activate
    Range("A2").PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Solution
Welcome to the MrExcel board!

There is generally no need to "activate" a sheet to work with it & activating is a relatively slow process & can make the screen flicker. It won't make any noticeable difference in what you are doing this time but I would suggest trying to learn to code without activating as much as possible.

Here is another option to try with a copy of your workbook.

VBA Code:
Sub CopyData()
  Dim lastRow As Long
  
  With Sheets("Sheet1")
    lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
    Sheets("Sheet2").Range("A2:A" & lastRow).Value = .Range("A2:A" & lastRow).Value
  End With
End Sub
 
Upvote 0
Thank you for both of your replies. They both fixed my problem. Much appreciated.
 
Upvote 0
Glad we could help. Thanks for letting us know. :)
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
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