-
calling subs from conditional statements
is there a more elegant way of writing this?
[vba]If chkBOM = False And chkpBOM = True And chkPO = True Then
Call getpBOM
Call getPO
ElseIf chkBOM = False And chkpBOM = True And chkPO = False Then
Call getpBOM
ElseIf chkBOM = False And chkPO = True And chkpBOM = False Then
Call getPO
ElseIf chkBOM = True And chkPO = False And chkpBOM = False Then
Call getBOM
ElseIf chkBOM = True And chkPO = True And chkpBOM = False Then
Call getBOM
Call getPO
ElseIf chkBOM = True And chkPO = False And chkpBOM = True Then
Call getBOM
Call getpBOM
ElseIf chkBOM = True And chkPO = True And chkpBOM = True Then
Call getBOM
Call getpBOM
Call getPO
End If[/vba]
-
Does it matter what order they're run in? Perhaps:
[VBA]If chkBom Then getBom
If chkpBom Then getpBom
If chkPo Then getPo[/VBA]
Richard
-
Try...
[VBA]
If chkpBOM And chkPO And Not chkBOM Then
Call getpBOM
Call getPO
ElseIf chkpBOM And Not (chkBOM Or chkPO) Then
Call getpBOM
ElseIf chkPO And Not (chkBOM Or chkpBOM) Then
Call getPO
ElseIf chkBOM And Not (chkPO Or chkpBOM) Then
Call getBOM
ElseIf chkBOM And chkpBOM And Not chkPO Then
Call getBOM
Call getpBOM
ElseIf chkBOM And chkPO And chkpBOM Then
Call getBOM
Call getpBOM
Call getPO
End If
[/VBA]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
-
-
cool guys, thanks for the help.
-
You can also apply integer values which provide unique solutions for each outcome
[vba]Sub SelectMacro()
If chkBOM Then a = 1
If chkpBOM Then b = 2
If chkPO Then c = 4
test = a + b + c
Select Case test
Case 1
Call getBOM
Case 2
Call getpBOM
Case 3
Call getBOM
Call getpBOM
Case 4
Call getPO
Case 5
Call getBOM
Call getPO
Case 6
Call getpBOM
Call getPO
Case 7
Call getBOM
Call getpBOM
Call getPO
End Select
End Sub
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Hey, Malcolm, neeto idea!
Sid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules