|
-
May 9th, 2005, 04:01 PM
#1
Thread Starter
New Member
IF statements with AND or OR
I know how to do IF statements in visual basic, but how do I incorporate AND and OR statements? ie, a simple if statement is:
if UserForm.CheckBox1 = True Then
statement
End If
But I want one that says:
if UserForm.CheckBox1 = True or if UserForm1.CheckBox 2 = True Then
statement
End If
and the same again, but using AND not or
Thanks for any help given.
Last edited by red6000; May 9th, 2005 at 05:48 PM.
-
May 9th, 2005, 04:12 PM
#2
Re: IF statements with AND or OR
Like this:
if UserForm.CheckBox1 = True or if UserForm1.CheckBox 2 = True Then
statement
End If
First OR then AND
VB Code:
if UserForm.CheckBox1 = True or _
UserForm1.CheckBox2 = True Then
' statement
End If
VB Code:
if UserForm.CheckBox1 = True and _
UserForm1.CheckBox2 = True Then
' statement
End If
-
May 9th, 2005, 04:21 PM
#3
Re: IF statements with AND or OR
Welcome to the forums red6000.
As a note, your "And" conditions need to come first before any "Or" conditions.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 05:18 PM
#4
Thread Starter
New Member
Re: IF statements with AND or OR
Thanks for the replies...
so lets say I want to process the statement if:
UserForm1.Checkbox1.Value = True AND UserForm1.Checkbox2.Value = True
OR if just UserForm1.Checkbox3.Value = True
as opposed to if:
UserForm1.Checkbox1.Value = True
AND if UserForm1.Checkbox2.Value = True OR if UserForm1.Checkbox3.Value = True
then how would it look? Could I have examples of both please if possible.
Hope that makes sense
Thanks for the help!!
-
May 9th, 2005, 05:23 PM
#5
Re: IF statements with AND or OR
I think I understand your request...
VB Code:
If ((UserForm1.Checkbox1.Value = True) AND (UserForm1.Checkbox2.Value = True)) OR (UserForm1.Checkbox3.Value = True) Then
'Either both the first two are checked OR just the third one
End If
If (UserForm1.Checkbox1.Value = True) AND (UserForm1.Checkbox2.Value = True) AND (UserForm1.Checkbox3.Value = True) Then
'All three are checked
End If
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 05:29 PM
#6
Thread Starter
New Member
Re: IF statements with AND or OR
The 2nd one was for the statement to be process if the 1st box is ticked and either of the other 2, so would it be:
VB Code:
If (UserForm1.Checkbox1.Value = True) AND ((UserForm1.Checkbox2.Value = True) OR (UserForm1.Checkbox3.Value = True)) Then
-
May 9th, 2005, 05:43 PM
#7
Re: IF statements with AND or OR
Correct. I wasnt too sure how you needed the grouping but you picked this up quite nicely.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 9th, 2005, 05:47 PM
#8
Thread Starter
New Member
Re: IF statements with AND or OR
Thanks for the help. That's going to make my code so much easier instead of using loads of nested IFs to get the same effect!
Thanks again.
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
|
Click Here to Expand Forum to Full Width
|