Compile error: invalid outside procedure

dowcraig

New Member
Joined
Jan 14, 2009
Messages
36
Hi there,
I'm making changes to row A, but am getting an invalid outside procedure, not sure why. Don't even know what it means. It's not even in the same worksheet.

This is my Macro:
' UpcomingClosings Macro
'
'
Range("B4:I100").Select
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add(Range( _
"H4:H100"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 255, 255)
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add Key:=Range _
("H4:H100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Upcoming Closings").Sort
.SetRange Range("B3:I100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
Where's the Sub... part of the code?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
You appear to be missing the Sub line at the start:
Code:
Sub UpcomingClosings()
 

dowcraig

New Member
Joined
Jan 14, 2009
Messages
36
Sorry, this is my macro:
Private Sub Workbook_BeforeSave(Cancel As Boolean)
'
' UpcomingClosings Macro
'
'
Range("B4:I100").Select
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add(Range( _
"H4:H100"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color _
= RGB(255, 255, 255)
ActiveWorkbook.Worksheets("Upcoming Closings").Sort.SortFields.Add Key:=Range _
("H4:H100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Upcoming Closings").Sort
.SetRange Range("B3:I100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

dowcraig

New Member
Joined
Jan 14, 2009
Messages
36
I really have no clue what I'm doing here.

Can I put a macro for each worksheet in their own respective worksheet in Microsoft Visual basic, or does it have to be in "This workbook". If it has to be in "this workbook, how do I put multiple ones?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Each worksheet has its own module - right-click the tab and choose View Code, or double-click the sheet in Project Explorer in the VBEditor.
Do you have anything else in the ThisWorkbook module?
 

dowcraig

New Member
Joined
Jan 14, 2009
Messages
36
My Microsoft Virtual Basic has the following tree:
- VBAProject (2009 Sales.xlsm)
- Sheet1 (2009)
- Sheet2 (Upcoming Closings)
- Sheet3 (Outstanding Gifts)
- Sheet4 (Referral Sources)
- Sheet5 (Referrals Out)
- ThisWorkbook
- Modules
- Module1
- Module2
- Module3
- Module4
- Module5
- Module6


Where can I put the Macro from the Upcoming Closings and Outstanding Gifts? Do they go in:
- Sheet2 (Upcoming Closings)
- Sheet3 (Outstanding Gifts)

or do they go in:
- ThisWorkbook
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
The Workbook_beforesave routine is an event routine and has to go in the thisworkbook module to be triggered when you save the workbook
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,323
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Yes, but the only ones that really belong there are workbook events like BeforeSave
 

Forum statistics

Threads
1,081,726
Messages
5,360,906
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top