VBA "mid" with "next I"

dukeofscouts

Board Regular
Joined
Jan 19, 2009
Messages
146
I'm trying to work on some VBA code that will allow me to type a text string, which excel will then "read" and perform a series of actions based on the characters in that text string. Below is what I tried, but I got an error message. My guess is I need to set the "i" value differently, any suggestions?

-Thanks much
--D.O.S.

Private Sub CommandButton2_Click()
For Each i In Rubrixform.TextBox1.Value
If Mid(Rubrixform.TextBox1.Value, i, 1) = "f" Then
If Mid(Rubrixform.TextBox1.Value, i+1, 1) = "'" Then
RubixFi
Else
RubixF
If Mid(Rubrixform.TextBox1.Value, i, 1) = "r" Then
If Mid(Rubrixform.TextBox1.Value, i+1, 1) = "'" Then
Rubixri
Else
Rubixr
If Mid(Rubrixform.TextBox1.Value, i, 1) = "u" Then
If Mid(Rubrixform.TextBox1.Value, i+1, 1) = "'" Then
RubixUi
Else
RubixU
If Mid(Rubrixform.TextBox1.Value, i, 1) = "d" Then
If Mid(Rubrixform.TextBox1.Value, i+1, 1) = "'" Then
Rubixdi
Else
Rubixd
If Mid(Rubrixform.TextBox1.Value, i, 1) = "l" Then
If Mid(Rubrixform.TextBox1.Value, i+1, 1) = "'" Then
Rubixli
Else
Rubixl
Next i
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Each of those IF's needs a matching End If.
With code like that, proper indenting makes it easier for you to read.
When posting on a message board, using code tags (and proper indenting) makes it easier for us to read.
 
Upvote 0
Private Sub CommandButton2_Click()
For Each i In Rubrixform.TextBox1.Value
If Mid(Rubrixform.TextBox1.Value, i, 1) = "f" Then
If Mid(Rubrixform.TextBox1.Value, i, 1) = "'" Then
RubixFi
Else
RubixF
End If
End If
...
Next i
End Sub
 
Upvote 0
Ok here is my latest rendition, still getting an error on it, but I think this is closer to what it should look like. I hope this idea is possible, and not just great theory that doesn't work.

Private Sub CommandButton2_Click()
For a_counter = 1 To Len(ribixfrom.TextBox1.Value)
If Mid(Rubrixform.TextBox1.Value, a_counter, 1) = "f" Then
If Mid(Rubrixform.TextBox1.Value, a_counter, 1) = "'" Then
RubixFi
Else
RubixF
End If
End If
...
end sub
 
Upvote 0
I GOT IT! the a_counter was the issue... thanks to every one for all the help you offered. Have a great week!
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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