This code is used to rearrange some columns, but it’s notworking properly?
Why is the following code working for the first worksheetbut not working for the second work sheet?
It scrambles up the first header row.
Thanks for any help.
Why is the following code working for the first worksheetbut not working for the second work sheet?
It scrambles up the first header row.
Code:
For i = 1 To ThisWorkbook.Sheets.Count
Sheets(i).Activate
With ActiveSheet
Dim arrColOrder As Variant, ndx As Integer
Dim Found As Range, counter As Integer
arrColOrder = Array("VolgCode", "Home", "Level", "Find No.", "Item Id", "Revision", "Change", "Item Name", "Qty")
counter = 1
Application.ScreenUpdating = False
For ndx = LBound(arrColOrder) To UBound(arrColOrder)
Set Found = Rows("1:1").Find(arrColOrder(ndx), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not Found Is Nothing Then
If Found.Column <> counter Then
Found.EntireColumn.Cut
Columns(counter).Insert Shift:=xlToRight
Application.CutCopyMode = False
End If
counter = counter + 1
End If
Next ndx
Application.ScreenUpdating = True
End With
Next i
Thanks for any help.