IIf(frmForm.opt

cmxulb

Board Regular
Joined
Nov 24, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hello,

This code below works, but if I add "both" it doesn't work

.Cells(iRow, 3) = IIf(frmForm.optLarge.Value = True, "Large", "Small") This code works


.Cells(iRow, 3) = IIf(frmForm.optLarge.Value = True, "Large", "Small", "Both") if I add "both" does not work.

How can I make it work by
Excel Formula:
adding "Both"?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
What are your possible values for optLarge? IIf stands for "Immediate IF"... is is basically and If..Then..Else..EndIf so it reacts to True and False only. You have a 3rd choice... what value chooses the "Both" response?
 
Upvote 0
What are your possible values for optLarge? IIf stands for "Immediate IF"... is is basically and If..Then..Else..EndIf so it reacts to True and False only. You have a 3rd choice... what value chooses the "Both" response?
Yea, true and false for large and small. but how can I make work with a 3rd choice?
 
Upvote 0
In order to answer that question, I need you to tell us what that third choice would be... True, False and.... what?

Also, how are these choices being delivered to you code procedure? Is the user selecting from a drop down, entering it into an InputBox, entering into a cell formatted as General, entering it into a cell formatted as Text, some other way?

Just out of curiosity, can you work with the three words (Large, Small, Both) directly?

If you tell us how the code you are asking about fits in your overall code procedure, it would help us in guiding you to the solution you are hoping to find.
 
Upvote 0
1618237666175.png


It works by selecting Scale small or large, but now I need to add Both. Selecting 1 only.

1618237788785.png
 
Upvote 0
Hi
try

VBA Code:
Cells(iRow, 3) = IIf(Me.optLarge.Value, "Large", IIf(Me.optBoth.Value, "Both", "Small"))

Dave
 
Upvote 0
Since these are option buttons, they will all have a value (True or False), so you can chain the IIF functions like this (I have assumed the name of your "small" OptionButton, change it if I guessed wrong)...
VBA Code:
.Cells(iRow, 3) = IIf(frmForm.optLarge.Value, "Large", IIf(frmForm.optSmall.Value, "Small", "Both))
Note: OptionButtons can only be True or False so you do not to test if it equals True or not.
 
Upvote 0
Hi
try

VBA Code:
Cells(iRow, 3) = IIf(Me.optLarge.Value, "Large", IIf(Me.optBoth.Value, "Both", "Small"))

Dave
yesss Thank You
This worked. took Me out add it FrmForm
View attachment 36500
Since these are option buttons, they will all have a value (True or False), so you can chain the IIF functions like this (I have assumed the name of your "small" OptionButton, change it if I guessed wrong)...
VBA Code:
.Cells(iRow, 3) = IIf(frmForm.optLarge.Value, "Large", IIf(frmForm.optSmall.Value, "Small", "Both))
Note: OptionButtons can only be True or False so you do not to test if it equals True or not.
Yessss Thank You! This worked.

1618240016109.png
 
Upvote 0
One last thing.
For validation, this is the code without "Both"
How can you make work with "Both"

'Validating Scale


If .optLarge.Value = False And .optSmall.Value = False Then

MsgBox "Please select scale.", vbOKOnly + vbInformation, "scale"
ValidatePrintDetails = False
Exit Function

End If
 

Attachments

  • 1618240226859.png
    1618240226859.png
    9.9 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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