I was wondering if there is a way to have my macro do the below:
I want it to run this code on sheet2:
Dim arrColOrder As Variant, ndx As Integer
Dim Found As Range, counter As Integer
'Place the column headers in the end result order you want.
arrColOrder = Array("*Item1*", "*Item2*", "*Item3*", "*Item4*")
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 Sub
Then run this code on sheet1:
'This will add three columns for the Item2, Item3, and the Item4 datapoints based on Item1 in column A.
Columns("P:P").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("P1").Select
ActiveCell.FormulaR1C1 = "Item4"
Columns("P:P").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("P1").Select
ActiveCell.FormulaR1C1 = "Item3"
Columns("P:P").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("P1").Select
ActiveCell.FormulaR1C1 = "Item2"
Range("P1:R1").Select
Range("R1").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("P2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[10],Sheet1!C[-15]:C[-14],2,FALSE)"
Range("P2").Select
Selection.AutoFill Destination:=Range("P2:P" & Cells(Rows.Count, "Z").End(xlUp).Row)
Range("Q2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[9],Sheet1!C[-16]:C[-14],3,FALSE)"
Range("Q2").Select
Selection.AutoFill Destination:=Range("Q2:Q" & Cells(Rows.Count, "Z").End(xlUp).Row)
Range("R2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[8],Sheet1!C[-17]:C[-14],4,FALSE)"
Range("R2").Select
Selection.AutoFill Destination:=Range("R2:R" & Cells(Rows.Count, "Z").End(xlUp).Row)
End Sub
Is there a way? So far all it does it run both on the active sheet and that makes everything mess up.
All I want is to re-order the things on sheet 2 so when I do the V lookup on sheet 1 they are in the right order!
Please help, thanks!