Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Moving Columns Macro

Hi, there.

I am attempting to set a macro to move columns in one spreadsheet to match
the column heading order in a different spreadsheet. If the secondary
spreadsheet always came in the same order, I could just move all of the
columns once and record the macro. However, the secondary spreadsheet column
headings are in no standard order once it is received, but must be in the
same order as the primary spreadsheet when finished. Is there a way I can
set up a macro to search for the column heading and then move it to the
appropriate place to be in the same order as the primary spreadsheet?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Moving Columns Macro

Here is a visual picture of what I am attempting to do:

Report Standard Column Headings
first_name last_name address state zip age birthdate
occupation

Report 1
last_name first_name age birthdate occupation address
state zip

Report 2
birthdate age occupation first_name last_name address state zip


Is this even possible? Any feedback would be greatly appreciated.
Thanks.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Moving Columns Macro

Hi miss_mas

If the sheet you want to normalise only has the columns you mentioned
you could move the columns into the correct order in another part of
the sheet. This code places the colmns in the correct order from Row
R onwards then deletes Column A to Q.

Hope this helps.

Marcus



Option Compare Text
Sub CorrectCol()

Dim Lastcol As Long

Lastcol = Cells(1, Columns.Count).End(xlToLeft).Column

For i = Lastcol To 1 Step -1
If Cells(1, i).Value = "first_name" Then
Cells(1, i).EntireColumn.Copy Columns("R:R")
ElseIf Cells(1, i).Value = "last_name" Then
Cells(1, i).EntireColumn.Copy Columns("S:S")
ElseIf Cells(1, i).Value = "address" Then
Cells(1, i).EntireColumn.Copy Columns("T:T")
ElseIf Cells(1, i).Value = "state" Then
Cells(1, i).EntireColumn.Copy Columns("U:U")
ElseIf Cells(1, i).Value = "zip" Then
Cells(1, i).EntireColumn.Copy Columns("V:V")
ElseIf Cells(1, i).Value = "birthdate" Then
Cells(1, i).EntireColumn.Copy Columns("W:W")
ElseIf Cells(1, i).Value = "age" Then
Cells(1, i).EntireColumn.Copy Columns("X:X")
ElseIf Cells(1, i).Value = "occupation" Then
Cells(1, i).EntireColumn.Copy Columns("Y:Y")
End If
Next i
Range("A:Q").EntireColumn.Delete
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Moving Columns Macro

This did the trick. It was exactly what I needed.
Marcus, you are awesome!!!!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Columns egrave Excel Discussion (Misc queries) 1 July 6th 08 11:09 PM
Moving columns about green biro Excel Programming 1 October 30th 07 10:54 PM
Need help with Macro in moving columns Brett Smith[_2_] Excel Programming 1 January 11th 06 06:48 PM
Moving Columns only hyyfte[_16_] Excel Programming 0 September 22nd 04 04:03 PM
Moving Columns gminor7 Excel Programming 2 September 12th 03 03:27 PM


All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"