Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code to Insert Formula in Cell

Example: I have one file with 2 worksheets (A and B). I want to have the
following formula in cell B10 of worksheet B: If range name RANGE1 on
worksheet A = 12, then insert the following text - "this is a test";
otherwise, insert a 0.

I had:
Worksheets("B").Range("B10").Formula = "=if('A'!RANGE1="12","this is a
test",0)"
but kept getting error messages. Tried with and without all types of quotes
and multiple other things, but still got various error messages like
application defined error, syntax error, or range property, etc.

Am I reference this correctly (obviously not). Also, where would this go -
into the module for worksheet B? What type of declaration (calculate?); I
may not have that correct either (tried all different kinds).

Appreciate any help that can be provided. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Code to Insert Formula in Cell

Hi Paige,

This works for me:

Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Example: I have one file with 2 worksheets (A and B). I want to have the
following formula in cell B10 of worksheet B: If range name RANGE1 on
worksheet A = 12, then insert the following text - "this is a test";
otherwise, insert a 0.

I had:
Worksheets("B").Range("B10").Formula = "=if('A'!RANGE1="12","this is a
test",0)"
but kept getting error messages. Tried with and without all types of
quotes
and multiple other things, but still got various error messages like
application defined error, syntax error, or range property, etc.

Am I reference this correctly (obviously not). Also, where would this
go -
into the module for worksheet B? What type of declaration (calculate?); I
may not have that correct either (tried all different kinds).

Appreciate any help that can be provided. Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code to Insert Formula in Cell

Rob, thanks. Does this go into the worksheet module? Under what type of
declaration? I'm still having problems and think it must be because I don't
have it in the right type of module or the correct declaration.

"Rob Bovey" wrote:

Hi Paige,

This works for me:

Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Example: I have one file with 2 worksheets (A and B). I want to have the
following formula in cell B10 of worksheet B: If range name RANGE1 on
worksheet A = 12, then insert the following text - "this is a test";
otherwise, insert a 0.

I had:
Worksheets("B").Range("B10").Formula = "=if('A'!RANGE1="12","this is a
test",0)"
but kept getting error messages. Tried with and without all types of
quotes
and multiple other things, but still got various error messages like
application defined error, syntax error, or range property, etc.

Am I reference this correctly (obviously not). Also, where would this
go -
into the module for worksheet B? What type of declaration (calculate?); I
may not have that correct either (tried all different kinds).

Appreciate any help that can be provided. Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Code to Insert Formula in Cell

Hi Paige,

It can go almost anywhere, it just needs to be run in order to work. The
simplest method is to add a regular code module to your project and put
something like the following procedure into it:

Public Sub EnterFormula()
Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"
End Sub

You can then run the EnterFormula procedure directly through the
Tools/Macro/Macros menu, you can assign it directly to a Button object from
the Forms toolbar or you can call it from any number of event procedures.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Rob, thanks. Does this go into the worksheet module? Under what type of
declaration? I'm still having problems and think it must be because I
don't
have it in the right type of module or the correct declaration.

"Rob Bovey" wrote:

Hi Paige,

This works for me:

Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Example: I have one file with 2 worksheets (A and B). I want to have
the
following formula in cell B10 of worksheet B: If range name RANGE1 on
worksheet A = 12, then insert the following text - "this is a test";
otherwise, insert a 0.

I had:
Worksheets("B").Range("B10").Formula = "=if('A'!RANGE1="12","this is a
test",0)"
but kept getting error messages. Tried with and without all types of
quotes
and multiple other things, but still got various error messages like
application defined error, syntax error, or range property, etc.

Am I reference this correctly (obviously not). Also, where would this
go -
into the module for worksheet B? What type of declaration
(calculate?); I
may not have that correct either (tried all different kinds).

Appreciate any help that can be provided. Thanks.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code to Insert Formula in Cell

Perfect! Thanks so much Rob. Have a great day......Paige

"Rob Bovey" wrote:

Hi Paige,

It can go almost anywhere, it just needs to be run in order to work. The
simplest method is to add a regular code module to your project and put
something like the following procedure into it:

Public Sub EnterFormula()
Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"
End Sub

You can then run the EnterFormula procedure directly through the
Tools/Macro/Macros menu, you can assign it directly to a Button object from
the Forms toolbar or you can call it from any number of event procedures.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Rob, thanks. Does this go into the worksheet module? Under what type of
declaration? I'm still having problems and think it must be because I
don't
have it in the right type of module or the correct declaration.

"Rob Bovey" wrote:

Hi Paige,

This works for me:

Worksheets("B").Range("B10").Formula = _
"=if(A!RANGE1=12,""this is a Test"",0)"

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Paige" wrote in message
...
Example: I have one file with 2 worksheets (A and B). I want to have
the
following formula in cell B10 of worksheet B: If range name RANGE1 on
worksheet A = 12, then insert the following text - "this is a test";
otherwise, insert a 0.

I had:
Worksheets("B").Range("B10").Formula = "=if('A'!RANGE1="12","this is a
test",0)"
but kept getting error messages. Tried with and without all types of
quotes
and multiple other things, but still got various error messages like
application defined error, syntax error, or range property, etc.

Am I reference this correctly (obviously not). Also, where would this
go -
into the module for worksheet B? What type of declaration
(calculate?); I
may not have that correct either (tried all different kinds).

Appreciate any help that can be provided. Thanks.






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
Formula, Macro, or VBA code to find and insert Keith Excel Worksheet Functions 3 October 2nd 09 08:21 PM
Insert text from one cell into formula in another cell. Deserthawk99 Excel Discussion (Misc queries) 2 March 1st 08 05:02 PM
Code To Insert Cell Reference Carl Bowman Excel Programming 6 February 13th 05 09:51 PM
Need code to insert cell value Steve Excel Programming 0 October 1st 04 12:00 AM
need code to insert cell value Steve Excel Programming 1 September 30th 04 11:38 PM


All times are GMT +1. The time now is 11:04 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"