If, ElseIf statements (multiple)

Formula11

Active Member
Joined
Mar 1, 2005
Messages
468
Office Version
  1. 365
Platform
  1. Windows
Is it possible to have an ElseIf statement on a single line?
An example is shown but each statement is on two lines.

Tried the following but did not work.

VBA Code:
If IsInArray(Character, Array01) = True Then: Increment = 1


VBA Code:
Function Size(Character As String) As Double
    Dim Increment As Double
    If IsInArray(Character, Array01) = True Then
        Increment = 1
    ElseIf IsInArray(Character, Array02) = True Then
        Increment = 1
    ElseIf IsInArray(Character, Array03) = True Then
        Increment = 5 / 6
    ElseIf IsInArray(Character, Array04) = True Then
        Increment = 2 / 3
    ElseIf IsInArray(Character, Array05) = True Then
        Increment = 1 / 2
    ElseIf IsInArray(Character, Array07) = True Then
        Increment = 1 / 3
    ElseIf IsInArray(Character, Array08) = True Then
        Increment = 1 / 6
    Else
        Increment = 1
    End If
    Size = Increment
End Function
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You could us a Select Case statement like
VBA Code:
   Select Case True
      Case IsInArray(Character, Array01): Increment = 1
      Case IsInArray(Character, Array02): Increment = 1
      Case IsInArray(Character, Array03): Increment = 5 / 6
   End Select
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,595
Members
452,657
Latest member
giadungthienduyen

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