Extracting Strings From A Single Dynamic String

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a string value that takes the form of ###/###.
I am looking for VBA code suggestions to isolate the numbers (as text) preceding the "/" and proceeding the "/", and then convert each to true numbers.
Both numeric values will be whole numbers, and could be of any length (value) from 1 - x digits.

Can anyone offer up a solution?

I have determined the position of the "/", and the length of the string (respectively) with this code:
Code:
spos = InStr(.Cells(srw, cl), "/")
slen = Len(.Cells(srw, cl))

Example 1:
string (from .cells(row,col)) = "32/3"
spos = 3
slen = 4
fwdnum = 32
bcknum = 3

Example 2:
string (from .cells(row,col)) = "1091/155"
spos = 5
slen = 8
fwdnum = 1091
bcknum = 155
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Perhaps:

VBA Code:
Sub SplitString()
Dim fwdnum As Long, bcknum As Long, str1 As String

    str1 = "12345/678"
 
    fwdnum = Left(str1, InStr(str1 & "/", "/") - 1)
    bcknum = Mid(str1, Len(fwdnum & "") + 2)

End Sub
 
Upvote 0
Solution
Like this?

VBA Code:
Sub test()

Dim str As String, fwdnum As Long, bcknum As Long

str = "123/456"

fwdnum = Split(str, "/")(0)
bcknum = Split(str, "/")(1)

MsgBox fwdnum
MsgBox bcknum

End Sub
 
Upvote 0
Thank you both! Each one appears to be providing the results I'm needing!
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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