Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 112
Default Macro to find and move column

Hi
I am wanting to run a macro that
1) finds specific text eg "XYZ"
2) select this entire column and cut
3) paste after the last column

I am using the find function as the column that XYZ appears in will vary in
different spreadsheets. There may be a better way?!

Thanks
Andrea
  #2   Report Post  
Posted to microsoft.public.excel.misc
JCS JCS is offline
external usenet poster
 
Posts: 93
Default Macro to find and move column

Andrea,

Try the following code. Copy and paste into the Microsoft Visual Basic
Editor. This code assumes that data are in contiguous columns. Please note
where you have to make changes to code. There are 3 places.

HTH.
John

Sub MoveColumn()
'

Dim FindWhat As Variant
Dim Col As Variant
Dim ColEnd As Variant
Dim ColLast As Variant

'Determines what column is to be moved and what column to move it to.

Application.ScreenUpdating = False
Range("a1").Select 'Replace with address of upper
corner of your table
Selection.CurrentRegion.Select
ColEnd = Selection.Columns.Count
ColLast = Mid(ActiveCell.Offset(0, ColEnd).Address, 2, 1)
Range("a1").Select 'Replace with address of upper
corner of your table

'Edit Find to search for string

FindWhat = Application.InputBox("Text", "Text")
Cells.Find(What:=FindWhat, After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate


'Moves column based on search string to column nect last column.

Col = Mid(ActiveCell.Address, 2, 1)
Columns(Col).Select
Selection.Cut Destination:=Columns(ColLast)
Range("a1").Select 'Replace with address of
upper corner of your table
Application.ScreenUpdating = True


End Sub

"andrea" wrote:

Hi
I am wanting to run a macro that
1) finds specific text eg "XYZ"
2) select this entire column and cut
3) paste after the last column

I am using the find function as the column that XYZ appears in will vary in
different spreadsheets. There may be a better way?!

Thanks
Andrea

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
Find account, move them to different sheet MACRO brodiemac Excel Discussion (Misc queries) 3 July 24th 08 07:49 PM
Find last column, move formulas over, copy/paste data Mike R. Excel Worksheet Functions 0 September 19th 07 06:40 AM
Move Column within Sheet with VB Macro Letzdo_1t Excel Discussion (Misc queries) 4 May 30th 07 11:43 PM
Macro to move to next column iblonger Excel Discussion (Misc queries) 9 January 3rd 06 05:18 PM
Macro - Find a value and then move down Phil Osman Excel Discussion (Misc queries) 4 August 10th 05 01:20 PM


All times are GMT +1. The time now is 05: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"