Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Using formula in code

I have the following formula which works fine in a worksheet:

=IF(AND(N4-1,N4<31)=TRUE,"1-30",IF(AND(N430,N4<61)=TRUE,"31-60",IF(AND(N460,N4<100)=TRUE,"61-99",IF(N499=TRUE,"100+","Error!"))))

However, when I try to use VBA code to enter the formula using this ( which
is basically the same thing)

Range("S2").FormulaR1C1 = _
"=IF(AND(RC[-1]-1,RC[-1]<31 = TRUE,"1", _
IF(AND(RC[-1]30,RC[-1]<61 =TRUE,"31-60", _
IF(AND(RC[-1]60,RC[-1]<100) =TRUE, "61-99", _
IF(RC[-1]99 = TRUE,"100+"."ERROR!"))))

I get a syntax error message

Can anyone tell me how to get it to enter the formual automatically please?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using formula in code

Hey Alan,

Try this

Range("A6").Select
ActiveCell.FormulaR1C1 = _

"=IF(AND(R[-1]C[1]-1,R[-1]C[1]<31)=TRUE,""1-30"",IF(AND(R[-1]C[1]30,R[-1]C[1]<61)=TRUE,""31-60"",IF(AND(R[-1]C[1]60,R[-1]C[1]<100)=TRUE,""61-99"",IF(R[-1]C[1]99=TRUE,""100+"",""Error!""))))"
Range("A6").Select

Regards
Subhash

"Alan M" wrote:

I have the following formula which works fine in a worksheet:

=IF(AND(N4-1,N4<31)=TRUE,"1-30",IF(AND(N430,N4<61)=TRUE,"31-60",IF(AND(N460,N4<100)=TRUE,"61-99",IF(N499=TRUE,"100+","Error!"))))

However, when I try to use VBA code to enter the formula using this ( which
is basically the same thing)

Range("S2").FormulaR1C1 = _
"=IF(AND(RC[-1]-1,RC[-1]<31 = TRUE,"1", _
IF(AND(RC[-1]30,RC[-1]<61 =TRUE,"31-60", _
IF(AND(RC[-1]60,RC[-1]<100) =TRUE, "61-99", _
IF(RC[-1]99 = TRUE,"100+"."ERROR!"))))

I get a syntax error message

Can anyone tell me how to get it to enter the formual automatically please?

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
How to code the formula? Eric Excel Discussion (Misc queries) 5 June 24th 09 04:41 PM
formula code nobbyknownowt Excel Discussion (Misc queries) 5 August 10th 06 05:40 PM
Formula to VB Code icetrey[_4_] Excel Programming 3 July 26th 06 08:34 AM
Code or Formula? Oggie Ben Doggie Excel Programming 4 November 16th 05 04:58 PM
SUM Formula using code Sony[_2_] Excel Programming 1 August 27th 03 09:34 AM


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