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 ever appear once in a cell):
extract_val(cell,start_str,end_str)
ie. extract_val(A1,"(",")") and give the results:
8,3
20
I only need to use this function within other vba code not by putting it as a formula on the sheet.
UPDATE (thanks to the answer, i settled on:)
---------------------------
Public Function extract_value(str As String) As String
Dim openPos As Integer
Dim closePos As Integer
Dim midBit As String
On Error Resume Next
openPos = InStr(str, "(")
On Error Resume Next
closePos = InStr(str, ")")
On Error Resume Next
midBit = mid(str, openPos + 1, closePos - openPos - 1)
If openPos <> 0 And Len(midBit) > 0 Then
extract_value = midBit
Else
extract_value = "F"
End If
End Function
Public Sub test_value()
MsgBox extract_value("NUMBER(9)")
End Sub