Matador_24
Board Regular
- Joined
- Dec 1, 2011
- Messages
- 205
Hello,
I am currently building a macro to extract a string from another string and store it in a variable, but I obtain the error: COMPILE ERROR: SUB OR FUNCTION NOT DEFINED and it highlights the word SEARCH in the formula.
What am I missing or how can I translate them into VBA language?
See formulas:
Moreover, I have these other two formulas that I need to use in another two variables and have the same issue:
=MID(A2,SEARCH("-",A2)+1,SEARCH("Books",A2)-SEARCH("-",A2)-2)
=IF(SUM(LEN(B2)-LEN(SUBSTITUTE(B2,{"0","1","2","3","4","5","6","7","8","9"},"")))>0, SUMPRODUCT(MID(0&B2, LARGE(INDEX(ISNUMBER(--MID(B2, ROW(INDIRECT("1:"&LEN(B2))), 1)) * ROW(INDIRECT("1:"&LEN(B2))), 0), ROW(INDIRECT("1:"&LEN(B2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(B2)))/10),"")
basically this is what the formulas do:
1st formula
String: SP 103 E 86 LLC (103e86st)
Formula:
=Mid(A1, Search("(", A1) + 1, Search(")", A1) - Search("(", A1) - 1)
Result: 103e86st
2nd formula:
String: Trial Balance For The Period January 2018 - March 2018 Books = Accrual, Eliminations
Formula:
=MID(A2,SEARCH("-",A2)+1,SEARCH("Books",A2)-SEARCH("-",A2)-2)
Result: March
3rd formula:
String: Trial Balance For The Period January 2018 - March 2018 Books = Accrual, Eliminations
Formula:
=IF(SUM(LEN(B2)-LEN(SUBSTITUTE(B2,{"0","1","2","3","4","5","6","7","8","9"},"")))>0, SUMPRODUCT(MID(0&B2, LARGE(INDEX(ISNUMBER(--MID(B2, ROW(INDIRECT("1:"&LEN(B2))), 1)) * ROW(INDIRECT("1:"&LEN(B2))), 0), ROW(INDIRECT("1:"&LEN(B2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(B2)))/10),"")
Result: 2018
I tested the formulas in excel and they work,
Thanks in advance!!
Luis
I am currently building a macro to extract a string from another string and store it in a variable, but I obtain the error: COMPILE ERROR: SUB OR FUNCTION NOT DEFINED and it highlights the word SEARCH in the formula.
What am I missing or how can I translate them into VBA language?
See formulas:
Code:
Sub Extractwords()
Dim Property As String
Property = Mid(A1, Search("(", A1) + 1, Search(")", A1) - Search("(", A1) - 1)
End Sub
Moreover, I have these other two formulas that I need to use in another two variables and have the same issue:
=MID(A2,SEARCH("-",A2)+1,SEARCH("Books",A2)-SEARCH("-",A2)-2)
=IF(SUM(LEN(B2)-LEN(SUBSTITUTE(B2,{"0","1","2","3","4","5","6","7","8","9"},"")))>0, SUMPRODUCT(MID(0&B2, LARGE(INDEX(ISNUMBER(--MID(B2, ROW(INDIRECT("1:"&LEN(B2))), 1)) * ROW(INDIRECT("1:"&LEN(B2))), 0), ROW(INDIRECT("1:"&LEN(B2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(B2)))/10),"")
basically this is what the formulas do:
1st formula
String: SP 103 E 86 LLC (103e86st)
Formula:
=Mid(A1, Search("(", A1) + 1, Search(")", A1) - Search("(", A1) - 1)
Result: 103e86st
2nd formula:
String: Trial Balance For The Period January 2018 - March 2018 Books = Accrual, Eliminations
Formula:
=MID(A2,SEARCH("-",A2)+1,SEARCH("Books",A2)-SEARCH("-",A2)-2)
Result: March
3rd formula:
String: Trial Balance For The Period January 2018 - March 2018 Books = Accrual, Eliminations
Formula:
=IF(SUM(LEN(B2)-LEN(SUBSTITUTE(B2,{"0","1","2","3","4","5","6","7","8","9"},"")))>0, SUMPRODUCT(MID(0&B2, LARGE(INDEX(ISNUMBER(--MID(B2, ROW(INDIRECT("1:"&LEN(B2))), 1)) * ROW(INDIRECT("1:"&LEN(B2))), 0), ROW(INDIRECT("1:"&LEN(B2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(B2)))/10),"")
Result: 2018
I tested the formulas in excel and they work,
Thanks in advance!!
Luis
Last edited: