Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting formulas to code tofimoon4 New Users to Excel 4 October 11th 10 01:01 PM
converting cell formulaes to code Hein Excel Worksheet Functions 3 October 21st 08 10:43 AM
Automatically Converting Formula in a Cell to its Value at the End of the Day Ronald Lawrence Excel Worksheet Functions 6 October 6th 05 09:59 PM
Converting cell contents to a formula Neil Excel Worksheet Functions 4 July 27th 05 06:27 AM
Converting code to R1C1 format Paul Excel Programming 1 April 15th 04 03:48 AM


All times are GMT +1. The time now is 03:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"