VBA/Macro help - Compile error

Tippelschniff

New Member
Joined
Sep 24, 2018
Messages
2
Hi all,

I have a dashboard that was changing column format when i refresh the data connection so have had a crack at recording a macro. i have no prior experience using macros and simply recorded steps (purely to amend col. formatting on opening of file) to give me the following. However when run it produces a "Compile error: expected End sub". Can anyone see the issue or educate me if there is a blinding error made?
Code:
Private Sub workbook_open()
Sub Convert_dates()
'
' Convert_dates Macro
' Converts date format to ddmmyyyy
'

'
    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 = 12
    ActiveWindow.ScrollColumn = 13
    Range("N:N,P:P,Q:Q,T:T,V:V").Select
    Range("Table_owssvr[[#Headers],[First Visit Date]]").Activate
    ActiveWindow.ScrollColumn = 14
    ActiveWindow.ScrollColumn = 15
    ActiveWindow.ScrollColumn = 16
    ActiveWindow.ScrollColumn = 17
    ActiveWindow.ScrollColumn = 18
    ActiveWindow.ScrollColumn = 19
    Range("N:N,P:P,Q:Q,T:T,V:V,Y:Y,AB:AB").Select
    Range("Table_owssvr[[#Headers],[Third Visit Date]]").Activate
    ActiveWindow.ScrollColumn = 20
    ActiveWindow.ScrollColumn = 21
    ActiveWindow.ScrollColumn = 22
    ActiveWindow.ScrollColumn = 23
    ActiveWindow.ScrollColumn = 24
    ActiveWindow.ScrollColumn = 25
    ActiveWindow.ScrollColumn = 26
    ActiveWindow.ScrollColumn = 27
    ActiveWindow.ScrollColumn = 28
    ActiveWindow.ScrollColumn = 29
    ActiveWindow.ScrollColumn = 30
    ActiveWindow.ScrollColumn = 31
    ActiveWindow.ScrollColumn = 32
    ActiveWindow.ScrollColumn = 33
    Range("N:N,P:P,Q:Q,T:T,V:V,Y:Y,AB:AB,AH:AH,AL:AL").Select
    Range("Table_owssvr[[#Headers],[Date Systems Updated]]").Activate
    ActiveWindow.ScrollColumn = 34
    ActiveWindow.ScrollColumn = 35
    ActiveWindow.ScrollColumn = 36
    Range("N:N,P:P,Q:Q,T:T,V:V,Y:Y,AB:AB,AH:AH,AL:AL,AM:AM,AO:AO").Select
    Range("Table_owssvr[[#Headers],[Modified]]").Activate
    ActiveWindow.ScrollColumn = 37
    ActiveWindow.ScrollColumn = 38
    Selection.NumberFormat = "m/d/yyyy"
End Sub
End Sub

Much appreciated in advance!
 
Last edited by a moderator:

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.
Welcome to the forum.

You can't put one sub inside another like that. You also have a lot of unnecessary lines there. Try this:

Code:
Private Sub workbook_open()
'
' Convert_dates Macro
' Converts date format to ddmmyyyy
'

'

    Range("N:N,P:P,Q:Q,T:T,V:V,Y:Y,AB:AB,AH:AH,AL:AL,AM:AM,AO:AO").NumberFormat = "m/d/yyyy"
End Sub
 
Upvote 0
Hi Rory - thank you yes I suspected my scrolling had no impact, much appreciated!

i assume i am able to stack sub-queries (once I've had a play with VBA and have some comprehension of the logic/syntax)?
 
Upvote 0
You can call multiple other macros from within a macro, you just can't define them within each other (well, you can using GoSub, but you shouldn't).
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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