Last Row is selecting an EXTRA 2000 rows.

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
So I'm looking to copy a range from a newly created, temporary query sheet to a permanent sheet with the code below. Hitting Control + End on the Query2 sheet brings me to I109, exactly what I would expect. Hovering over the LR variable in the code shows 109. Debug.printing the variable shows 109. Yet, for reasons I can't understand, when I try to copy the range, the program is selecting all the way down to row 2109. Can anyone offer any ideas as to what I'm doing wrong?

Thanks!

...Mike

Code:
Sub Copy_PasteDataToMainTab() 'This copies the current payroll data from the filtered query into the "Main" payroll tab.


Dim LR As Long
Dim ws2 As Worksheet
Dim ws As Worksheet


Set ws2 = Worksheets("Query2")
Set ws = Worksheets("Main")


ws.Activate


LR = ws2.Cells(Rows.Count, 1).End(xlUp).Row


Application.ScreenUpdating = False


ws2.Activate
      
      Range("A2:G2" & LR).Copy
      ws.Range("A" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValuesAndNumberFormats  '----> Copies values and number formats only to Main starting in Column A
   
ws.Activate


Application.ScreenUpdating = True
Application.CutCopyMode = False
Range("D1").Select


Call RowColor


End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Re: Last Row is selecting an EXTRA 2000 rows... Please help.

On this line
Code:
Range("A2:G2" & LR).Copy
you are concatenating G2 with the value of LR, ie G2109
Simply remove the 2 after the G
 
Upvote 0
Re: Last Row is selecting an EXTRA 2000 rows... Please help.

You're awesome Fluff! Worked perfectly. Thanks for such a quick reply. That had been torturing me for a couple of hours...

...Mike
 
Upvote 0
Re: Last Row is selecting an EXTRA 2000 rows... Please help.

Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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