E
EagleOne
I appreciate the time and effort that you expended. Sincerely, I hope that we all have gained from
same.
EagleOne
same.
EagleOne
Joel said:the subroutine main was just a test driver to demostrate the code worked.
when working with cells functtions can only return one value. Somehow you
need to get it to return two values. In this case I would add another input
parameter to indicate if you want the left side or right side of the parse.
=Parse("*","L",String) or
=Parse("*","R",String)
Function Parse(ParseChar As String, ReturnHalf as String, String1 as String)
If StrComp(Left(String1, 1), ParseChar) = 0 Then
String1 = Mid(String1, 2)
End If
CharCount = 1
Do While StrComp(Mid(String1, CharCount, 1), ParseChar) <> 0
If StrComp(Mid(String1, CharCount, 1), "'") = 0 Then
CharCount = CharCount + 1
Do While Mid(String1, CharCount, 1) <> "'"
CharCount = CharCount + 1
Loop
End If
CharCount = CharCount + 1
Loop
if ReturnHalf = "R" Then
Parse = Mid(String1, CharCount + 1)
else
Parse = Left(String1, CharCount - 1)
end if
End Function
[email protected] said:Joel,
Thanks so much for your time and knowledge.
I am in the midst of assimilating your code.
How can I use the code when the order/number of the operators is variable.
i.e. assume that I have only two cell ref's separated by the "/" operator.
Please do not take this as critical. This code will absolutely work for the hardcoded
StringA. How can I adapt the code for use on any formula cell?
EagleOne
Joel said:I like these type problems
Sub main()
Dim StringA As String
Dim StringB As String
StringA = "+123456789+'Summary 2-22-2007'!H8+'Summary 3-22-2007
'!H22-A1+(144/6)*'Summary 4-22-2007'!H23-B1+9876"
StringB = ""
Call Parse("+", StringA, StringB)
StringA = StringB
Call Parse("+", StringA, StringB)
StringA = StringB
Call Parse("-", StringA, StringB)
StringA = StringB
Call Parse("+", StringA, StringB)
StringA = StringB
Call Parse("*", StringA, StringB)
StringA = StringB
Call Parse("-", StringA, StringB)
StringA = StringB
Call Parse("+", StringA, StringB)
End Sub
Sub Parse(ParseChar As String, ByRef String1, ByRef String2)
If StrComp(Left(String1, 1), ParseChar) = 0 Then
String1 = Mid(String1, 2)
End If
CharCount = 1
Do While StrComp(Mid(String1, CharCount, 1), ParseChar) <> 0
If StrComp(Mid(String1, CharCount, 1), "'") = 0 Then
CharCount = CharCount + 1
Do While Mid(String1, CharCount, 1) <> "'"
CharCount = CharCount + 1
Loop
End If
CharCount = CharCount + 1
Loop
String2 = Mid(String1, CharCount + 1)
String1 = Left(String1, CharCount - 1)
End Sub
:
Thanks for the time.
The dashes in dates are not being skipped but intentionally avoided by skipping over anything
between " ' " and " '! ".
Frankly it is a VBA issue if one has to program this parsing challenge, in VBA.
This isn't a VBA problem, it is a linear algebra problem with no real answer.
To get a unique answer your grammar must be defined better. Dashes are in
dates and are being skipped because of the single quotes. Rules like these
need to be defined.
2003/2007
Trying to consistently parse formula strings (Delimiter = any Opr sign) into i.e.
OprSigns = Array("+", "-", "*", "/", "^", ">", "<", "<>", ">=", "<=")
FormulaStr = "+123456789+'Summary 2-22-2007'!H8+'Summary 3-22-2007 '!H22- _
A1+(144/6)*'Summary 4-22-2007'!H23-B1+9876"
All formulas will begin (stuffed) with "+" sign if not already a "-" [if this makes parsing easier]
Goal:
Operator
Parsed(1) = 123456789 +
Parsed(2) = 'Summary 2-22-2007'!H8 +
Parsed(3) = 'Summary 3-22-2007'!H22 -
Parsed(4) = A1 +
Parsed(5) = (144/6) *
Parsed(6) = Summary 4-22-2007'H23 -
Parsed(7) = B1 +
Parsed(8) = 9876 end of FormulaStr
It is important to isolate, for later retrieval, each operator AFTER each Parsed(x)
Attempted (looooose VBA) Split(FormulaStr, OprSigns,1,1)
Another challenge, avoiding sign-look-a-like characters between each " ' " followed by " ' ! " or
in the Path to other workbooks (still within " ' " followed by " ' ! " I believe) Eg., would be
the "-" in dates like above.
The approach I tried was to avoid parsing between " ' " followed by " ' ! " as Gap(1), Gap(2), etc.
I can get very close but I need someone with much better VBA skills to get the gold ring.
Thanks for any thoughts, approaches or cuss words.
EagleOne