Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Set cell formulas using code? how?

Hi,

I see from the Excel help that you can set formulas, but when I tried to set
the following formula:

Worksheets("Sheet1").Range("A1").Formula = "=+IF(B1 < "",(B1-1)*1000 +
(1000-C1),"")"

it didn't work? I get run-time error 1004 "Application defined or object
defined error"

Any ideas?

Thanks in advance,

Reedi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Set cell formulas using code? how?

First, ditch the =+. That marks you as a Lotus-holdout.

The problem you're having is that quotation marks in VBA designate
the start and end of a string of text. To refer to quotation marks
*within* a string of text, you need to double them (""):

Worksheets("Sheet1").Range("A1").Formula = _
"=IF(B1< """", (B1-1)*1000+(1000-C1), """")"

which could be more simply written:

Worksheets("Sheet1").Range("A1").Formula = _
"=IF(B1< """", B1 * 1000 - C1, """")"



In article ,
"Reedi" wrote:

Hi,

I see from the Excel help that you can set formulas, but when I tried to set
the following formula:

Worksheets("Sheet1").Range("A1").Formula = "=+IF(B1 < "",(B1-1)*1000 +
(1000-C1),"")"

it didn't work? I get run-time error 1004 "Application defined or object
defined error"

Any ideas?

Thanks in advance,

Reedi


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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
delete some cell formulas and leave others using code john tempest Excel Worksheet Functions 0 February 23rd 06 03:51 PM
Code to delete rows and column cells that have formulas in. GarToms Excel Worksheet Functions 1 January 18th 06 01:04 PM
Copy formulas via Code Cordobes Excel Discussion (Misc queries) 1 December 11th 05 02:51 PM


All times are GMT +1. The time now is 12:16 PM.

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

About Us

"It's about Microsoft Excel"