Stupid Question About Copying Rows

beartooth91

New Member
Joined
Dec 15, 2024
Messages
9
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hello Everyone -

New to the forum, but have been writing VBA for several years.

I have what is likely a stupid question in regards to copying rows.....

See the two code snips below. They do not do the same thing and I don't understand why.

Specifically, the two range statements are different, but I can't figure out why they act different. May I ask someone here to explain?

Thanks


Dim c As Long

c = Workbooks("Master Database.xlsm").Worksheets("Inputs").Range("B" & Rows.Count).End(xlUp).Row
'
'Copy Point Name
'Workbooks("Master Database.xlsm").Worksheets("Inputs").Range("B11" & c).Copy '<-----doesn't work, copies a blank cell

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

'Copy Point Name

Workbooks("Master Database.xlsm").Worksheets("Inputs").Activate

Workbooks("Master Database.xlsm").Worksheets("Inputs").Range("B11", Range("B" & Rows.Count).End(xlUp)).Copy
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In the 1st code, if the last row was row 1000 you are writing

VBA Code:
Range("B111000")

it should be

VBA Code:
Range("B11:B" & c)
 
Upvote 0
In the 1st code, if the last row was row 1000 you are writing

VBA Code:
Range("B111000")

it should be

VBA Code:
Range("B11:B" & c)
Yeah, I don't get it. To me, both look like they should be selecting the same cell/range. The top piece selects "B823" and the bottom VBA selects "B8:B23".
 
Upvote 0
both look like they should be selecting the same cell/range.

No in your first code you are concatenating the last row number to B11 and so if the last row was 9999 you are writing B119999 not B11:B9999.... it needs to be B11:B not just B11


Edit:

In your last example you are concatenating 23 to B8 so you get B823 not B8:B23
 
Last edited:
Upvote 0
No in your first code you are concatenating the last row number to B11 and so if the last row was 9999 you are writing B119999 not B11:B9999.... it needs to be B11:B not just B11


Edit:

In your last example you are concatenating 23 to B8 so you get B823 not B8:B23
Uh-Oh....
So, I've been thinking this entire time that the '&' operator adds the two. You're saying it joins the range and last row integer, end to end......(?)
 
Upvote 0
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
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