DG...
DG...

Reputation: 11

VBA Compile Error: Invalid Outside Procedure

I'm trying to create and run a pretty simple macro in Excel 2016, but I keep getting the following error message "Compile Error: Invalid Outside Procedure.

All the macro is trying to do is when I click a button on one worksheet, the macro moves to another worksheet, and amends a filter on a particular column (and removes the zero's from the column).

I've recorded the macro to do this, but when I assign it to a button and try to run it, the error keeps coming up.

The code shown in the VBA tab is as follows:

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Can someone help as it's driving me nuts!

Thank you

Upvotes: 1

Views: 10711

Answers (2)

VBABeginner
VBABeginner

Reputation: 125

It could be just as easy as deleting the first 'End Sub' in your code.

w1n5rx seems to be correct with completing your code to perfom what you're describing.

But maybe other options to try: Maybe try the active controlx button <--- or however its labeled.

or try

Static Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Upvotes: 0

vsr
vsr

Reputation: 1137

Half code (or incomplete code) is like half-truth, difficult to understand or judge. So, if I understand your question here's the (probable) solution. 1. On the button click method, write the sheet change code (e.g. Sheets("books").Select) 2. Once the intended sheet is selected, select the column you want to apply filter on by simply recording the macro. 3. Then do the rest of the tasks. These are simple steps. If you still don't succeed then please revert.

Upvotes: 1

Related Questions