excel vba- extract text between 2 characters

前端 未结 4 877
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 15:35

If i had this column:

ColA
-----
NUMBER(8,3)
NUMBER(20)

I need a VBA function that would go (note these start and end string would only eve

4条回答
  •  孤街浪徒
    2020-12-01 15:53

    You can use instr to locate a character within the string (returning the position of '(' for example). You can then use mid to extract a substing, using the positions of '(' and ')'.

    Something like (from memory):

    dim str as string
    dim openPos as integer
    dim closePos as integer
    dim midBit as string
    
    str = "NUMBER(8,3)"
    openPos = instr (str, "(")
    closePos = instr (str, ")")
    midBit = mid (str, openPos+1, closePos - openPos - 1)
    

    You may want to add error checking in case those characters don't occur in the string.

提交回复
热议问题