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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Where's the Sub... part of the code?
 
Upvote 0
You appear to be missing the Sub line at the start:
Code:
Sub UpcomingClosings()
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
The Workbook_beforesave routine is an event routine and has to go in the thisworkbook module to be triggered when you save the workbook
 
Upvote 0
Yes, but the only ones that really belong there are workbook events like BeforeSave
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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