PDA

View Full Version : Solved: Find "-" position in text



Cass
10-27-2005, 11:30 PM
Hello!

How find witch position is "-" in text "30-0,55-16,5" in VBA!!
first i need only the first "-". Later the second "-" also

reason why i need this is dissever the text:
30
0,55

BlueCactus
10-27-2005, 11:38 PM
This will work for two. If you have more than two, you'll soon want a more elegant solution...

myString = "30-0,55-16,5"
firstPos = InStr(myString, "-")
secondPos = InStr(InStr(myString, "-") + 1, myString, "-")

Cass
10-27-2005, 11:44 PM
thanks so fast answer http://vbaexpress.com/forum/images/smilies/023.gif

Bob Phillips
10-28-2005, 01:43 AM
This will work for two. If you have more than two, you'll soon want a more elegant solution...

myString = "30-0,55-16,5"
firstPos = InStr(myString, "-")
secondPos = InStr(InStr(myString, "-") + 1, myString, "-")


Without re-inventing the wheel


Sub GetValues()
Dim ary
Dim i As Long
ary = Split(ActiveCell.Value, "-")
For i = LBound(ary) To UBound(ary)
MsgBox ary(i)
Next i
End Sub