Macro Help: using my last row variable to copy a specific range of cells from one col. to another

RoccoM

New Member
Joined
Apr 22, 2019
Messages
19
Very new to Macros and VBA.
I have managed to find my total rows in my sheet, and I have that number stored in a variable.
I need help with using this variable to copy a specific range from one column of my sheet to another column in the same sheet.

here is what I have so far.

Dim MyRow As Long

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


The MyRow variable contains the value 64842

So here is where I need some help.

For example I would like to use the variable to help me copy a specific range from one column to another column.

so let's say I want to copy row 2 to 100 from column a and copy them into column AA2
or I want to copy all of the rows in column A (minus A1, because I have headings) to Column Z row 2

How can I use a variable to copy specific rows?

Thanks for the help,
Rocco
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
so let's say I want to copy row 2 to 100 from column a and copy them into column AA2

In this example is row 100 the last row (your variable Myrow) or are you trying to paste the 99 rows of data to the next row after the last row in AA2. I am a bit confused by your explanation. It is not clear what actions you want to take. Let's take baby steps to explain in detail the actions you wish to take.
 
Upvote 0
Thanks for the reply.

I found out how many rows my sheet contains, and I stored into a variable called MyRow. As of right now my sheet contains 64842 rows. The number of rows can change based on data; sometimes more, sometimes less.
My sheet contains column headings in row 1.

I want to use my variable to create a range of cells in a specific column.
Since I do not know how many rows I will have (each time I create the sheet), I will use the variable to know how many rows that I have.
Remember that I need to exclude the first row because it contains headings not data.

So let's say that I want to copy data from a specific column, for a specific range, and I need to paste that data into another column in the same sheet.
something like this. copy paste B2:B64842 to Z2:Z64842

Using my variable, how can I do this?

thank you,
Rocco
 
Upvote 0
How about
Code:
Sub RoccoM()
   Dim MyRow As Long
   
   MyRow = Cells(Rows.Count, 1).End(xlUp).Row
   Range("B2:B" & MyRow).Copy Range("Z2")
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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