Hello
Have simple macros which compares two sheets of data, clearing out redundant columns and adding a VLOOKUP and it works fine, however, it only works the first time I run it, if I re-enter fresh data and run again it doesn't work.
Pretty new to macros, what's wrong?
Here's the code bit....
Sub meetasreport()
'
' meetasreport Macro
' compares wp8 against fta
'
'
Columns("A:O").Select
Range("O1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Delete Shift:=xlToLeft
Columns("C:K").Select
ActiveWindow.SmallScroll Down:=-27
Selection.Delete Shift:=xlToLeft
Columns("C:K").EntireColumn.AutoFit
Columns("E:H").Select
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("E:F").Select
Range("F1").Activate
Selection.Delete Shift:=xlToLeft
Columns("G:H").Select
Range("H1").Activate
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("G:H").EntireColumn.AutoFit
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
Columns("H:R").Select
Range("R1").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll ToRight:=-7
Columns("B:B").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Sheets("fta").Select
Columns("A:O").Select
Range("O1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Cells.Select
Selection.RowHeight = 16.5
Columns("C:K").Select
Range("K1").Activate
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("E:J").Select
Selection.Delete Shift:=xlToLeft
Columns("E:J").EntireColumn.AutoFit
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
Columns("I:T").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-2
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C[-1],'wp8'!C[-1]:C,2,FALSE)"
Selection.AutoFill Destination:=Range("B1:B851")
Range("B1:B851").Select
Range("B1").Select
ActiveWorkbook.Worksheets("fta").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("fta").Sort.SortFields.Add Key:=Range("B1"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("fta").Sort
.SetRange Range("A1:I851")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=594
End Sub
Any help greatly appreciated.
Using excel 2010.
Have simple macros which compares two sheets of data, clearing out redundant columns and adding a VLOOKUP and it works fine, however, it only works the first time I run it, if I re-enter fresh data and run again it doesn't work.
Pretty new to macros, what's wrong?
Here's the code bit....
Sub meetasreport()
'
' meetasreport Macro
' compares wp8 against fta
'
'
Columns("A:O").Select
Range("O1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Delete Shift:=xlToLeft
Columns("C:K").Select
ActiveWindow.SmallScroll Down:=-27
Selection.Delete Shift:=xlToLeft
Columns("C:K").EntireColumn.AutoFit
Columns("E:H").Select
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("E:F").Select
Range("F1").Activate
Selection.Delete Shift:=xlToLeft
Columns("G:H").Select
Range("H1").Activate
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("G:H").EntireColumn.AutoFit
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
Columns("H:R").Select
Range("R1").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll ToRight:=-7
Columns("B:B").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Sheets("fta").Select
Columns("A:O").Select
Range("O1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:J").Select
Range("J1").Activate
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Cells.Select
Selection.RowHeight = 16.5
Columns("C:K").Select
Range("K1").Activate
ActiveWindow.SmallScroll Down:=-3
Selection.Delete Shift:=xlToLeft
Columns("E:J").Select
Selection.Delete Shift:=xlToLeft
Columns("E:J").EntireColumn.AutoFit
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
Columns("I:T").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-2
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C[-1],'wp8'!C[-1]:C,2,FALSE)"
Selection.AutoFill Destination:=Range("B1:B851")
Range("B1:B851").Select
Range("B1").Select
ActiveWorkbook.Worksheets("fta").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("fta").Sort.SortFields.Add Key:=Range("B1"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("fta").Sort
.SetRange Range("A1:I851")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=594
End Sub
Any help greatly appreciated.
Using excel 2010.