Macro to Move Column to Another Sheet Based on Header

Michael151

Board Regular
Joined
Sep 20, 2010
Messages
247
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> Hello all,

Trying to write a macro that will find the column labeled “notes” (in row 1 header) in the worksheet labeled “Full Report”, copy this entire column, then move the column to the worksheet “Secondary Report” and place in column E.

Any help is greatly appreciated – thank you!
 
Alex - this code is perfect! How can I modify it so that I can add more vba code once it is done moving the columns? When I replace "End Sub" with Exit Sub, it goes back to the start instead of executing the remaining the vba code. Below is how I changed the end of your code & then added some of what I need to happen next.
Thank you!
PB

(Sub CopyColumns() .......)NextOne:


Next i


ErrHandler:
MsgBox "Could not find " & Titles(i)
Resume NextOne


Exit Sub




' Prepare the Upload Sheet
With Sheets("Upload").Select
Rows("1:12").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
End With
End Sub
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,

If I understand correctly the following code should work:

Code:
Option Explicit

Sub CopyColumn()

'Note if there is more than one notes column in Full Report this will move the first

'Select Full Report Sheet
Sheets("Full Report").Select

'Find Notes column and copy
Cells.find(What:="Notes", After:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows).EntireColumn.Copy

'Select Secondary Report sheet, column E and paste
Sheets("Secondary Report").Select
Range("E1").Select
ActiveSheet.Paste
Application.CutCopyMode = False

End Sub

Any questions please let me know.

Cheers,
alx7000

Alex,

Is there a way to modify this to select only cells that display data.
Take out the .Entirecolumn.copy and add a range (active cell & row.count).end(xlup).row?

Is this possible because after copying the entire column excel will not paste in the WS with a greater cell count than the new sheet.

Thank you,
 
Upvote 0
Hi Alex,

Thanks for the above VB Code.

However , Kindly let me know how to extend the coding for below two points with the same code provided by you above.

Point 1 : In the source sheet i have 50000 rows & 35 columns in which i want to copy & paste only respective columns for which you have already advised with the code above , in the same i have a column AL , which contains correct values and also "NA" , while copying all the columns i want to exclude the rows which contains "NA" from getting copied and pasted in my target sheet.
Point 2: Also i want the target sheet to be created as a separate file and get saved in the specific location with specific name.

Kindly advise.

Thanks in advance for your help!
Jeetesh
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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