Borsuk Ulam
New Member
- Joined
- Aug 5, 2011
- Messages
- 4
Hi, im trying to write a recursive function to reformat some data in excel.
This is my first function i ever wrot using vb.
I have used Scheme in school when learning how to write recursive functions.
this is what i wrote
Function f(cell)
If cell = "" Then
f = cell
ElseIf Left(cell, 1) = " " Then
f = f(Replace(cell, 1, 1, ""))
ElseIf Left(cell, 1) = "," Then
f = f(Replace("cell", 1, 1, ""))
ElseIf Left(cell, 1) = "." Then
f = f(Replace(cell, 1, 1, ""))
ElseIf Left(cell, 54) = "BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE, EXPIRY DATE" Then
f = "2 " & " " & f(Replace(cell, 1, 54, ""))
ElseIf Left(cell, 40) = "BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE" Then
f = "1 " & " " & f(Replace(cell, 1, 40, ""))
ElseIf IsNumeric(Left(cell, 1)) Then
f = f(Replace(cell, 1, 1, ""))
ElseIf left(cell,2) = "TO" Then
f(Replace(cell,1,2,"")
f = Left(cell, 4) & " " & f(Replace(cell, 1, 4, ""))
End If
End Function
My function if given
TP21, TP75, TP05, TP19, TMT1, T115, TP11, TP01 TO 20110802, BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE, EXPIRY DATE TP79, TL59 TO 20110802
should produce
TP21 TP75 TP05 TP19 TMT1 T115 TP11 TP01 2 TP79 TL59
instead i get #value
If there was more information i should provide, let me know.
Thanks for your help.
This is my first function i ever wrot using vb.
I have used Scheme in school when learning how to write recursive functions.
this is what i wrote
Function f(cell)
If cell = "" Then
f = cell
ElseIf Left(cell, 1) = " " Then
f = f(Replace(cell, 1, 1, ""))
ElseIf Left(cell, 1) = "," Then
f = f(Replace("cell", 1, 1, ""))
ElseIf Left(cell, 1) = "." Then
f = f(Replace(cell, 1, 1, ""))
ElseIf Left(cell, 54) = "BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE, EXPIRY DATE" Then
f = "2 " & " " & f(Replace(cell, 1, 54, ""))
ElseIf Left(cell, 40) = "BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE" Then
f = "1 " & " " & f(Replace(cell, 1, 40, ""))
ElseIf IsNumeric(Left(cell, 1)) Then
f = f(Replace(cell, 1, 1, ""))
ElseIf left(cell,2) = "TO" Then
f(Replace(cell,1,2,"")
f = Left(cell, 4) & " " & f(Replace(cell, 1, 4, ""))
End If
End Function
My function if given
TP21, TP75, TP05, TP19, TMT1, T115, TP11, TP01 TO 20110802, BOTH PRODUCT AND DISCOUNT EFFECTIVE DATE, EXPIRY DATE TP79, TL59 TO 20110802
should produce
TP21 TP75 TP05 TP19 TMT1 T115 TP11 TP01 2 TP79 TL59
instead i get #value
If there was more information i should provide, let me know.
Thanks for your help.