Indigenous
07-18-2018, 02:17 AM
If you have many if statements which are similar, would you use "Select Case", another function, or something else?
My code is in progress but looks something like this.
The only variation is the character, which may be "A", "B", "C", etc.
If (CLoc > 0 And InStr(1, TextLeft, "A") <> 0 And CharLeft = "A") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
If (CLoc > 0 And InStr(1, TextLeft, "B") <> 0 And CharLeft = "B") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
If (CLoc > 0 And InStr(1, TextLeft, "C") <> 0 And CharLeft = "C") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
'etc
'Attempt with Case Select
Dim Char As String
Select Case Char
Case "A", "B", "C" 'etc
If (CLoc > 0 And InStr(1, TextLeft, Char) <> 0 And CharLeft = Char) Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
Case Else
Msgbox "No"
End Select
My code is in progress but looks something like this.
The only variation is the character, which may be "A", "B", "C", etc.
If (CLoc > 0 And InStr(1, TextLeft, "A") <> 0 And CharLeft = "A") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
If (CLoc > 0 And InStr(1, TextLeft, "B") <> 0 And CharLeft = "B") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
If (CLoc > 0 And InStr(1, TextLeft, "C") <> 0 And CharLeft = "C") Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
'etc
'Attempt with Case Select
Dim Char As String
Select Case Char
Case "A", "B", "C" 'etc
If (CLoc > 0 And InStr(1, TextLeft, Char) <> 0 And CharLeft = Char) Then
Cell.Characters(.SelStart + 1, 0).Insert "Test text"
End If
Case Else
Msgbox "No"
End Select