Consulting

Results 1 to 4 of 4

Thread: Solved: Find "-" position in text

  1. #1
    VBAX Regular
    Joined
    Aug 2005
    Posts
    77
    Location

    Solved: Find "-" position in text

    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

  2. #2
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    This will work for two. If you have more than two, you'll soon want a more elegant solution...

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

  3. #3
    VBAX Regular
    Joined
    Aug 2005
    Posts
    77
    Location
    thanks so fast answer

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by BlueCactus
    This will work for two. If you have more than two, you'll soon want a more elegant solution...

    [vba] myString = "30-0,55-16,5"
    firstPos = InStr(myString, "-")
    secondPos = InStr(InStr(myString, "-") + 1, myString, "-")
    [/vba]
    Without re-inventing the wheel

    [VBA]
    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
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •