Need Code to run 2 different macros

HK kemp

New Member
Joined
Aug 31, 2014
Messages
7
Hi i have been searching and trying to make this possible i hope you guys can help me.

1. Cell "X8" recieves a logical return of "TRUE" or "FALSE" from a drop down list
2. The "TRUE" return needs to run "Makro1"
3. The "FALSE" return needs to run "Makro2"
(4). Both macro redesigns the sheet, i dont know if you need this info or not.

The codes i have tried seems to skip one of the macros, i have also put each macro in their own modules.

I know its a simple code, and its probably starring me right in the face, but i appreciate every help i can get

Thank in advance :)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Something along these lines?

Sub trueorfalse()

Dim test As Boolean
test = Sheets("Sheet 1").activexnamehere.Value

If arg1 = True Then
Call trueroutine
End If

If arg1 = False Then
Call falseroutine

End Sub
 
Upvote 0
Thanks for the reply

Dosent seem to work

1. I was not clear on this. When referring to the "X8" cell it needs to be in a fixed sheet in the book, meaning ppl will be able to delete sheets not needed.
2. Tried variations of this, and similar

Private Sub Worksheet_Change(ByVal Target As Range)
If [X8] = True then
Call Makro1
End If

If [X8] = False Then
Call Makro2
End If

End Sub

This however only seems to run the last makro, or infact both macros at the same time
 
Upvote 0
Try...

Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
If Range("X8").Value = True Then
Makro1
Else
Makro2
End If
End Sub
 
Upvote 0
thx Brück this works

However it run the macros upon change in any cell, allthough which macro run is determined by "X8", i need it to only run the macros upon change in "X8", and not when i do other work in other cells
 
Upvote 0
Sorry, my fault for doing it on the fly without testing. I missed a line. Try...

Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
[COLOR=#ff0000]If Not Intersect(Target, Range("X8")) Is Nothing Then[/COLOR]
If Range("X8").Value = "True" Then
Makro1
Else
Makro2
End If
End If
End Sub
 
Upvote 0
Thanks for the response

This addition dosent work

Cell "X8" only recieves the true or false state from a dropmenu elsewhere on the sheet, and to clarify the true or false macros are used to redesign the worksheet to either one or the other, i was thinking to incorperate a Boolean test, but cant figure out how to make it all work.

:) i know it should be straight forward but right now its giving me more grey hairs :)
 
Upvote 0
Why not forgo X8 and just reference the true or false value of your Form or ActiveX control?

Rather than updating everything whenever the worksheet is changed, this will allow you to trigger the macros when the control is changed. Just put some code into the WorkSheet code to call your macros. If you're using a combobox, then it might look something like this.

Code:
Private Sub ComboBox1_Change()
Application.ScreenUpdating = False

If Sheet("SheetNameHere").ComboBox1.Value = True Then
    Call TrueRoutine
Else
    If Sheet("SheetNameHere").ComboBox1.Value = False Then
        Call FalseRoutine
    End If
End If

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Spacebouncer

Thanks for responding that dosent work here, let me clarify.

1. Drop down menu has multiple selections
2. Each selection has its own logical true/false test in W8:W25, this is due to each selection corresponding to certain values which needs to be generated
3. The X8 cell has a logical test which goes =OR($W$9:$W$25)
4. If W8 is true the sheet needs to generate one type of table (Makro1)
5. If any of the W9:W25 is true the sheet needs to generate another type of table (Makro2)

Therefor X8 True/false state is paramount to the function, i know i can use W8's state but to be safe i want to run it off X8 :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,326
Members
448,564
Latest member
ED38

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