Hello all,
I am trying to trim text that is in a column with a consistent header name in the worksheets but will be in different column locations (for instance sometimes in column AY and sometimes in column AZ). This is the macro I recorded where I searched for the column header name, inserted a column next to it then did text to columns to separate them at the point I wanted them to separate at. Is there any way to get this to where it would work even when the column with that column name is in a different spot?
Thanks,
Jordan
Sub Trim_Text()
'
' Trim_Date Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Selection.Find(What:="ColumnHeaderName", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Columns("AZ:AZ").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("AY:AY").Select
Selection.TextToColumns Destination:=Range("AY1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(9, 1)), TrailingMinusNumbers:=True
End Sub
I am trying to trim text that is in a column with a consistent header name in the worksheets but will be in different column locations (for instance sometimes in column AY and sometimes in column AZ). This is the macro I recorded where I searched for the column header name, inserted a column next to it then did text to columns to separate them at the point I wanted them to separate at. Is there any way to get this to where it would work even when the column with that column name is in a different spot?
Thanks,
Jordan
Sub Trim_Text()
'
' Trim_Date Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Selection.Find(What:="ColumnHeaderName", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Columns("AZ:AZ").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("AY:AY").Select
Selection.TextToColumns Destination:=Range("AY1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(9, 1)), TrailingMinusNumbers:=True
End Sub