Even and Odd digits

Fyr

Active Member
Joined
Jan 20, 2009
Messages
375
I have a textbox1 that accepts Number digits only.
I want to take the value of textbox1 and separate the even and odd digits.
For Example:
Textbox1.value is 1000107113646084
Even digits numbers are 00013404
Odd digits numbers are 10171668

How would I go about doing that?

Thanks for taking a look!:)
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:

Code:
Public Sub SplitEvenOdd()
Dim EvenNum As String, _
    OddNum  As String, _
    i       As Long
    
For i = 1 To Len(textbox1.Value)
    If Right(i, 1) Like [13579] Then
        OddNum = OddNum & Mid$(textbox1.Value, i, 1)
    Else
        EvenNum = EvenNum & Mid$(textbox1.Value, i, 1)
    End If
Next i
    
End Sub
 
Upvote 0
If you mean the 2nd, 4th, 6th... and 1st, 3rd, 5th... characters then this should work.
Code:
Private Sub CommandButton1_Click()
 
    strs = TextBox1.Value
 
    For i = 1 To Len(strs) Step 2
        strOdd = strOdd & Mid(strs, i, 1)
        strEven = strEven & Mid(strs, i + 1, 1)
    Next i
 
    TextBox2.Value = strEven
 
    TextBox3.Value = strOdd
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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