macros works fine the first time it's run the second time - doesn't?

skinpup

New Member
Joined
Sep 6, 2012
Messages
25
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.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
So, after a cleanup we have this.....what are you actually trying to do ???

Code:
Sub meetasreport()
Columns("A:O").Delete Shift:=xlToLeft
Columns("A:J").Delete Shift:=xlToLeft
Columns("C:K").Delete Shift:=xlToLeft
Columns("C:K").EntireColumn.AutoFit
Columns("E:H").Delete Shift:=xlToLeft
Columns("E:F").Delete Shift:=xlToLeft
Columns("G:H").Delete Shift:=xlToLeft
Columns("G:H").EntireColumn.AutoFit
Columns("H:R").Delete Shift:=xlToLeft
Columns("B:B").Cut
Columns("A:A").Insert Shift:=xlToRight
Sheets("fta").Columns("A:O").Delete Shift:=xlToLeft
Columns("A:J").Delete Shift:=xlToLeft
Columns("B:B").Cut
Columns("A:A").Insert Shift:=xlToRight
Cells.RowHeight = 16.5
Columns("C:K").Delete Shift:=xlToLeft
Columns("E:J").Delete Shift:=xlToLeft
Columns("E:J").EntireColumn.AutoFit
Columns("H:H").Delete Shift:=xlToLeft
Columns("I:T").Delete Shift:=xlToLeft
Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1:B851").FormulaR1C1 = "=VLOOKUP(C[-1],'wp8'!C[-1]:C,2,FALSE)"
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
End Sub
 
Upvote 0
Compare customer code number which appears in both 'fta' and 'wp8' sheets. I need to know which customers in the fta list don't appear in the wp8 list, which it does, but only the first time I run it.
 
Upvote 0
So why are you deleting heaps of columns ??
Can I suggest, explaining what you actually need to do in detail, and let posters here work out the code rather than posting recorded code that doesn't seem to make sense ... :wink:
 
Upvote 0
Apologies.
That's just the way the data exports from the company reporting system. Have found the solution from somewhere else... ask a mate who designs databases!!! Doh, don't know why I never thought of it in the first place.
Thanks for taking the time to look at my question anyway. Off to learn about inner joins...
Martin
 
Upvote 0
NO worries...glad you got it sorted..(y)
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,750
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top