Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Trying to move columns based on heading text, PLEASE HELP

Just like the Subject line says, I am trying to move whole columns around
based on the heading text. So, if heading text says "Accession number" I
want it to be in column E, and if it says X, I want it to be in column A.
Basically we will be getting files from somebody and the columns may not
always be aligned to the code I have already written, so I would like to have
code to look at the first row and based on what it says in the first row,
move whole columns in order without deleting any of the records. How can I
do this? Any help would be greatly appreciated. THANKS!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Trying to move columns based on heading text, PLEASE HELP

Instead of moving the columns I might recomend creating a new sheets and
copying the columns over in the proper order. That way if something goes
wrong you have not messed up your source data (I am always leary about
playing with the original data, because I have seen it messed up far too
often). Here is some code to create a new sheet and move the columns over in
the proper order...

Sub FormatData()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngHeadings As Range
Dim rngCurrent As Range

Set wksCurrent = ActiveSheet 'Could be any sheet you want
Set wksNew = Worksheets.Add
With wksCurrent 'Assume headings are in row 1
Set rngHeadings = .Range(.Range("A1"), .Cells(1,
Columns.Count).End(xlToLeft))
End With
For Each rngCurrent In rngHeadings
Select Case rngCurrent.Value
Case "This" 'Heading This Goes to C
rngCurrent.EntireColumn.Copy wksNew.Columns("C")
Case "That" 'Heading That Goes to B
rngCurrent.EntireColumn.Copy wksNew.Columns("B")
Case "The Other" 'Heading The Other Goes to A
rngCurrent.EntireColumn.Copy wksNew.Columns("A")
End Select
Next rngCurrent

End Sub
--
HTH...

Jim Thomlinson


"Brett Smith" wrote:

Just like the Subject line says, I am trying to move whole columns around
based on the heading text. So, if heading text says "Accession number" I
want it to be in column E, and if it says X, I want it to be in column A.
Basically we will be getting files from somebody and the columns may not
always be aligned to the code I have already written, so I would like to have
code to look at the first row and based on what it says in the first row,
move whole columns in order without deleting any of the records. How can I
do this? Any help would be greatly appreciated. THANKS!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Trying to move columns based on heading text, PLEASE HELP

Wow Jim, thanks. I'm gonna try this out and modify it to fit my needs.
Thanks, I really appreciate it.

Brett

"Jim Thomlinson" wrote:

Instead of moving the columns I might recomend creating a new sheets and
copying the columns over in the proper order. That way if something goes
wrong you have not messed up your source data (I am always leary about
playing with the original data, because I have seen it messed up far too
often). Here is some code to create a new sheet and move the columns over in
the proper order...

Sub FormatData()
Dim wksCurrent As Worksheet
Dim wksNew As Worksheet
Dim rngHeadings As Range
Dim rngCurrent As Range

Set wksCurrent = ActiveSheet 'Could be any sheet you want
Set wksNew = Worksheets.Add
With wksCurrent 'Assume headings are in row 1
Set rngHeadings = .Range(.Range("A1"), .Cells(1,
Columns.Count).End(xlToLeft))
End With
For Each rngCurrent In rngHeadings
Select Case rngCurrent.Value
Case "This" 'Heading This Goes to C
rngCurrent.EntireColumn.Copy wksNew.Columns("C")
Case "That" 'Heading That Goes to B
rngCurrent.EntireColumn.Copy wksNew.Columns("B")
Case "The Other" 'Heading The Other Goes to A
rngCurrent.EntireColumn.Copy wksNew.Columns("A")
End Select
Next rngCurrent

End Sub
--
HTH...

Jim Thomlinson


"Brett Smith" wrote:

Just like the Subject line says, I am trying to move whole columns around
based on the heading text. So, if heading text says "Accession number" I
want it to be in column E, and if it says X, I want it to be in column A.
Basically we will be getting files from somebody and the columns may not
always be aligned to the code I have already written, so I would like to have
code to look at the first row and based on what it says in the first row,
move whole columns in order without deleting any of the records. How can I
do this? Any help would be greatly appreciated. THANKS!

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
move text & numbers in column to separate columns deb Excel Discussion (Misc queries) 5 January 16th 09 05:31 AM
Macro-delete & move heading Nikki Excel Discussion (Misc queries) 2 July 31st 06 04:21 PM
Deleting Columns Based upon Heading Jessica Excel Programming 2 November 3rd 05 11:05 PM
How do I get a column heading to show up at the top and not move . Need help guy Excel Discussion (Misc queries) 2 February 24th 05 07:11 PM
Sending macro based e-mail with built-in "Heading" and "Text" Prabha Excel Programming 3 January 17th 05 02:11 PM


All times are GMT +1. The time now is 11:36 PM.

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

About Us

"It's about Microsoft Excel"