MS Excel macro to copy only specific columns

Azrin

New Member
Joined
Mar 5, 2012
Messages
16
Hello everyone. :)

I need your help in building a macro that would allows me to copy specific colums from one workbook to another workbook.

The first worksheet consists of Column A until Column DJ. A lots, rite. :p

Of all of these columns, I just want to copy Column C, D, & AD until DH.

The columns will be copied to a new worksheet in a different workbook.

Hence, is there any macro that able to help me accomplish this?

Thanks. :)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Plus, I only want to copy the column begining from cells C6 until the last row of data in that column.
This also applied to the rest of the columns.
 
Upvote 0
Does this help?

Code:
Sub azrin()

Dim lr As Long

FirstWorkbook.Activate

lr = Cells(Rows.Count, 3).End(xlUp).Row

Range("C6:D" & lr).Copy Anotherworkbook.Sheets("Sheet1").Range("C6")
Range("AD6:DH" & lr).Copy Anotherworkbook.Sheets("Sheet1").Range("AD6")


End Sub
 
Upvote 0
Hi John. :)

Thank you so much for the solution.

Yes, it works great. All I need to change is put the workbook name inside Workbooks(firstworkbook). Activate

One more request if you don't mind, I forgot to mention that the first 2 columns (C & D) contain VLookup formulae. :p

Hence, everytime I run the macro to copy them, #REF! error appeared, can you show how to copy only cell values from the macro that you have provided?

Once again, thank you. :)
 
Last edited:
Upvote 0
You're welcome. Glad to hear we are on the right track:

Maybe:

Code:
Sub azrin()

Dim lr As Long
Dim x As Long

Workbooks(FirstWorkbook).Activate

lr = Cells(Rows.Count, 3).End(xlUp).Row

x = Range("C6:C" & lr).Rows.Count

Anotherworkbook.Sheets("Sheet1").Range("C6").Resize(x, 2).Value = Range("C6:D" & lr).Value
Range("AD6:DH" & lr).Copy Anotherworkbook.Sheets("Sheet1").Range("AD6")


End Sub
 
Upvote 0
It Works!!! Thank you so much, John!

Hi John. :)

Thank you so much for the solution. :)
The code works wonder.

You are my hero and saviour! :biggrin:

Hope you have lots of great days and to other Excel's user who facing similar problem like me, I do hope that the solution provided by John, help you as well.

:)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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