Hi All,
I am trying to rearrange the order of columns A to K with a macro, I have copied the following from somewhere else and has worked on a different sheet, but I am now getting a
"Run time error 91 - object variable or with bock variable not set" -
each time i run it on the current one. I am not familiar with VBA, any help is very much appreciated.
Dim v As Variant, x As Variant, findfield As Variant
Dim oCell As Range
Dim iNum As Long
v = Array("EMPLOYER", "NAME", "FAMILY NAME", "FIRST NAME", "CLAIM ID", "PAID FROM", "PAID TO", "CHQ DRAWN DATE", "AMOUNT PAID", "PAYMENT TYPE", "PAYEE")
For x = LBound(v) To UBound(v)
findfield = v(x)
iNum = iNum + 1
Set oCell = ActiveSheet.Rows(1).Find(What:=findfield, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not oCell.Column = iNum Then
Columns(oCell.Column).Cut
Columns(iNum).Insert Shift:=xlToRight
End If
Next x
Cheers Hawkster
I am trying to rearrange the order of columns A to K with a macro, I have copied the following from somewhere else and has worked on a different sheet, but I am now getting a
"Run time error 91 - object variable or with bock variable not set" -
each time i run it on the current one. I am not familiar with VBA, any help is very much appreciated.
Dim v As Variant, x As Variant, findfield As Variant
Dim oCell As Range
Dim iNum As Long
v = Array("EMPLOYER", "NAME", "FAMILY NAME", "FIRST NAME", "CLAIM ID", "PAID FROM", "PAID TO", "CHQ DRAWN DATE", "AMOUNT PAID", "PAYMENT TYPE", "PAYEE")
For x = LBound(v) To UBound(v)
findfield = v(x)
iNum = iNum + 1
Set oCell = ActiveSheet.Rows(1).Find(What:=findfield, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not oCell.Column = iNum Then
Columns(oCell.Column).Cut
Columns(iNum).Insert Shift:=xlToRight
End If
Next x
Cheers Hawkster