Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
Greetings,
I have a formula that is working well in a cell that I need to convert to VBA code. Here is the ordinal cell formula broken out logically: IF(G216="", E216&IF(C216="", IF(D216="", "", ", "&D216), IF(D216="", ", "&C216, ", "&C216&" & "&D216)), G216) Here is the conversion from cells to TextBoxes: C216 = TextBox2 D216 = TextBox3 E216 = TextBox4 G216 = TextBox6 I need to put the result of this formula into TextBox7 Any help would be most appreciated. TIA =Minitman |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
Dim msg as String
IF Textbox6.Text = "" Then msg = Textbox4.Text IF Textbox2.Text = "" THen IF Textbox3.Text ="" then msg = msg Else msg = msg & ", " & Textbox3.Text End if Else IF Textbox3.Text = "" then msg = msg & ", " & Textbox2.Text Else msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else msg = Textbox6.Text End If TextBox7.Text = msg -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy "Minitman" wrote in message ... Greetings, I have a formula that is working well in a cell that I need to convert to VBA code. Here is the ordinal cell formula broken out logically: IF(G216="", E216&IF(C216="", IF(D216="", "", ", "&D216), IF(D216="", ", "&C216, ", "&C216&" & "&D216)), G216) Here is the conversion from cells to TextBoxes: C216 = TextBox2 D216 = TextBox3 E216 = TextBox4 G216 = TextBox6 I need to put the result of this formula into TextBox7 Any help would be most appreciated. TIA =Minitman |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
Thanks Tom,
For some reason this one had me stumped. It must be that I could not get the cell logic out of my mind. Thank you, this helps a lot. -Minitman On Wed, 3 Nov 2004 12:27:17 -0500, "Tom Ogilvy" wrote: Dim msg as String IF Textbox6.Text = "" Then msg = Textbox4.Text IF Textbox2.Text = "" THen IF Textbox3.Text ="" then msg = msg Else msg = msg & ", " & Textbox3.Text End if Else IF Textbox3.Text = "" then msg = msg & ", " & Textbox2.Text Else msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else msg = Textbox6.Text End If TextBox7.Text = msg -- Regards, Tom Ogilvy |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
Hey Tom,
Sorry this took so long, had to work on other projects. I tried to run this code and I kept getting a: Compile error: Else without If The debugger then high lights this line: ( the word Else) ....(from the code below) msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else <<<<<<<< msg = Textbox6.Text End If TextBox7.Text = msg I can't see what is wrong with this code!!! Can anyone tell me why I keep getting this error? TIA -Minitman On Wed, 3 Nov 2004 12:27:17 -0500, "Tom Ogilvy" wrote: Dim msg as String IF Textbox6.Text = "" Then msg = Textbox4.Text IF Textbox2.Text = "" THen IF Textbox3.Text ="" then msg = msg Else msg = msg & ", " & Textbox3.Text End if Else IF Textbox3.Text = "" then msg = msg & ", " & Textbox2.Text Else msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else msg = Textbox6.Text End If TextBox7.Text = msg -- Regards, Tom Ogilvy |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
Left out an End if:
Private Sub CommandButton1_Click() Dim msg As String If TextBox6.Text = "" Then msg = TextBox4.Text If TextBox2.Text = "" Then If TextBox3.Text = "" Then msg = msg Else msg = msg & ", " & TextBox3.Text End If Else If TextBox3.Text = "" Then msg = msg & ", " & TextBox2.Text Else msg = msg & ", " & TextBox2.Text _ & " & " & TextBox3.Text End If End If Else msg = TextBox6.Text End If TextBox7.Text = msg End Sub -- Regards, Tom Ogilvy "Minitman" wrote in message ... Hey Tom, Sorry this took so long, had to work on other projects. I tried to run this code and I kept getting a: Compile error: Else without If The debugger then high lights this line: ( the word Else) ...(from the code below) msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else <<<<<<<< msg = Textbox6.Text End If TextBox7.Text = msg I can't see what is wrong with this code!!! Can anyone tell me why I keep getting this error? TIA -Minitman On Wed, 3 Nov 2004 12:27:17 -0500, "Tom Ogilvy" wrote: Dim msg as String IF Textbox6.Text = "" Then msg = Textbox4.Text IF Textbox2.Text = "" THen IF Textbox3.Text ="" then msg = msg Else msg = msg & ", " & Textbox3.Text End if Else IF Textbox3.Text = "" then msg = msg & ", " & Textbox2.Text Else msg = msg & ", "& Textbox2.Text _ & " & " & Textbox3.Text End if Else msg = Textbox6.Text End If TextBox7.Text = msg -- Regards, Tom Ogilvy |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Converting Cell Formula To VBA Code
No problem - Thanks Tom
-Minitman On Thu, 4 Nov 2004 08:39:37 -0500, "Tom Ogilvy" wrote: Left out an End if: Private Sub CommandButton1_Click() Dim msg As String If TextBox6.Text = "" Then msg = TextBox4.Text If TextBox2.Text = "" Then If TextBox3.Text = "" Then msg = msg Else msg = msg & ", " & TextBox3.Text End If Else If TextBox3.Text = "" Then msg = msg & ", " & TextBox2.Text Else msg = msg & ", " & TextBox2.Text _ & " & " & TextBox3.Text End If End If Else msg = TextBox6.Text End If TextBox7.Text = msg End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
converting formulas to code | New Users to Excel | |||
converting cell formulaes to code | Excel Worksheet Functions | |||
Automatically Converting Formula in a Cell to its Value at the End of the Day | Excel Worksheet Functions | |||
Converting cell contents to a formula | Excel Worksheet Functions | |||
Converting code to R1C1 format | Excel Programming |