In VBA how can I select all columns but one?
I need to select all of my columns except for Time_Stamp, and have all of the the select columns set to to text.
Range("A:W,Y:Z").Select
Range("A:W,Y:Z").Select
Selection.NumberFormat = "@"
Sub test()
Dim Except As Long, LC As Long, j
Except = Rows(1).Find(what:="Time_Stamp", LookIn:=xlValues, lookat:=xlWhole).Column
LC = Cells(1, Columns.Count).End(xlToLeft).Column
For j = 1 To LC
If j <> Except Then Columns(j).NumberFormat = "@"
Next j
End Sub
Are you saying that Cell 1 in each column contains a heading?Sorry my columns change order, meaning what is A one day might be C the next, so I was looking to select all omitting the Time_Stamp column.... by "set to text," I meant to format all of those columns to text.
Thanks for your help!
Peter you are too quick!! I was stumbling my way through writing something much less concise.Maybe like this
Code:Sub test() Dim Except As Long, LC As Long, j Except = Rows(1).Find(what:="Time_Stamp", LookIn:=xlValues, lookat:=xlWhole).Column LC = Cells(1, Columns.Count).End(xlToLeft).Column For j = 1 To LC If j <> Except Then Columns(j).NumberFormat = "@" Next j End Sub