If statement, Result=Macro

ShaunD30

Board Regular
Joined
Jun 19, 2008
Messages
172
I am setting up some Macros on my worksheet. Is it possible to write an IF statement that states

=IF(C12="x",Begin MacroX,IF(C12="y",Begin MacroY,MacroF)


Thanks,


Shaun
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If the values are being typed into C12 then you could try this. Right click the sheet tab and select View Code. Paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "C12" Then
    Select Case Target.Value
        Case "x"
            Call MacroX
        Case "y"
            Call MacroY
        Case Else
            Call MacroF
    End Select
End If
End Sub
 
Upvote 0
The values will be in c-12 in the form of a validation list. I tried your idea and it works perfectly. Thank you very much :)

Shaun
 
Upvote 0
Ok So I got this to work just the way I wanted it to, however..

Here is my issue. I have 2 worksheets. Worksheet 1 is a summary of the data on worksheet 2. The Macro's I have recorded are simple copy and paste functions. When the data is selected within the validation list, that data causes the corresponding macro to run. The Macro copies the specified data from sheet 2 and pastes it onto sheet 1. Works like a charm.

The problem is that for that split second when the macro runs, you can see the workbook jump from worksheet 1 to worksheet 2 when it copies and pastes the specified data.

Is there a way to do this without seeing that "worksheet jump"? It's OK if there isn't, just curious though because it's semi-annoying.

Shaun
 
Upvote 0
Is there a way to do this without seeing that "worksheet jump"? It's OK if there isn't, just curious though because it's semi-annoying.

2 methods...

1 (easiest)
Code:
Application.ScreenUpdating = False
rest of code
Application.ScreenUpdating = True
2 (best)
Rewrite code so that it doesn't Select/Activate Sheets...

For example..
Instead of
Code:
Sheets("Sheet1").Select
Range("A1").Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
you can just say
A = B
like
Code:
Sheets("Sheet2").Range("A1").Value = Sheets("Sheet1").Range("A1").Value
 
Upvote 0
I honestly don't know what I would do without this message board.

For this workbook I am going to do the "Easiest" method. In the future, I am going to use your "best" method of starting out with a better coded macro :)

Thank you guys so much for making my life easier.

Shaun
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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