Kenja824
Automotive
- Nov 5, 2014
- 950
I have this bit of code to find one of several texts inside a cell and return the one it finds.
Currently it finds the text at the end of the string of text in the cell. How can I adjust this to find the text anywhere within the cell?
Currently the cell may be AA150_R01_B03 and so it returns the B03 at the end.
What if the cell contains... AA150_R01_B03_Common but I still want to return the B03. How do you write the formula to look for the string fo text anywhere in the cells data?
Public Function Xtract(t As String) As String
Dim Area(1 To 48) As String
Dim s As String
Area(1) = "B01"
Area(2) = "B02"
Area(3) = "B03"
Area(4) = "B04"
Area(5) = "B05"
Area(6) = "B06"
Area(7) = "B07"
Area(8) = "B08"
s = ""
For i = 1 To 8
If InStr(1, t, Area(i)) > 0 Then
s = s & ", " & Area(i)
End If
Next i
Xtract = Right(s, Len(s) - 1)
End Function
Currently it finds the text at the end of the string of text in the cell. How can I adjust this to find the text anywhere within the cell?
Currently the cell may be AA150_R01_B03 and so it returns the B03 at the end.
What if the cell contains... AA150_R01_B03_Common but I still want to return the B03. How do you write the formula to look for the string fo text anywhere in the cells data?
Public Function Xtract(t As String) As String
Dim Area(1 To 48) As String
Dim s As String
Area(1) = "B01"
Area(2) = "B02"
Area(3) = "B03"
Area(4) = "B04"
Area(5) = "B05"
Area(6) = "B06"
Area(7) = "B07"
Area(8) = "B08"
s = ""
For i = 1 To 8
If InStr(1, t, Area(i)) > 0 Then
s = s & ", " & Area(i)
End If
Next i
Xtract = Right(s, Len(s) - 1)
End Function