Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find account, move them to different sheet MACRO | Excel Discussion (Misc queries) | |||
Find last column, move formulas over, copy/paste data | Excel Worksheet Functions | |||
Move Column within Sheet with VB Macro | Excel Discussion (Misc queries) | |||
Macro to move to next column | Excel Discussion (Misc queries) | |||
Macro - Find a value and then move down | Excel Discussion (Misc queries) |