Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 50
Default Formula within a Macro not working as expected.

I recorded a macro that inserts the following formula in cell R2:-

Range("R2").Select
ActiveCell.Formula = "=IF(ISBLANK(P2),"""",1000-P2)"

I then wanted to insert another formula in R3 and the macro recorded it as :-

Range("R3").Select
ActiveCell.Formula = "=IF(ISBLANK(P3),"""",(R2-P3))"

However when the macro has completed, and I look in cell R3 the formula
reads:-

=IF(ISBLANK(P3),"",1000-P3)

It should say =IF(ISBLANK(P3),"",(R2-P3))

What do I need to change in the macro so that the formula is as I want?

Please also note the next step in the macro is to FILL the formula from cell
R3 to R50 using:-

Selection.AutoFill Destination:=Range("R2:R50"), Type:=xlFillDefault

Any help offered will be appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 5,441
Default Formula within a Macro not working as expected.

Pank,

Your line:
Selection.AutoFill Destination:=Range("R2:R50"), Type:=xlFillDefault

Should be:
Selection.AutoFill Destination:=Range("R3:R50"), Type:=xlFillDefault

Though there is no need to select:

Sub NewSub()
Range("R2").Formula = "=IF(ISBLANK(P2),"""",1000-P2)"
Range("R3").Formula = "=IF(ISBLANK(P3),"""",(R2-P3))"
Range("R3").AutoFill Destination:=Range("R3:R50"), Type:=xlFillDefault
End Sub

HTH,
Bernie
MS Excel MVP


"Pank" wrote in message
...
I recorded a macro that inserts the following formula in cell R2:-

Range("R2").Select
ActiveCell.Formula = "=IF(ISBLANK(P2),"""",1000-P2)"

I then wanted to insert another formula in R3 and the macro recorded it as
:-

Range("R3").Select
ActiveCell.Formula = "=IF(ISBLANK(P3),"""",(R2-P3))"

However when the macro has completed, and I look in cell R3 the formula
reads:-

=IF(ISBLANK(P3),"",1000-P3)

It should say =IF(ISBLANK(P3),"",(R2-P3))

What do I need to change in the macro so that the formula is as I want?

Please also note the next step in the macro is to FILL the formula from
cell
R3 to R50 using:-

Selection.AutoFill Destination:=Range("R2:R50"), Type:=xlFillDefault

Any help offered will be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 50
Default Formula within a Macro not working as expected.

Bernie,

Firstly, Apologies for not coming back to you sooner. (Have been on holiday
for a few days). The changes you recommended worked perfectly as expected.

Secondly, Thank you for you time.


"Bernie Deitrick" wrote:

Pank,

Your line:
Selection.AutoFill Destination:=Range("R2:R50"), Type:=xlFillDefault

Should be:
Selection.AutoFill Destination:=Range("R3:R50"), Type:=xlFillDefault

Though there is no need to select:

Sub NewSub()
Range("R2").Formula = "=IF(ISBLANK(P2),"""",1000-P2)"
Range("R3").Formula = "=IF(ISBLANK(P3),"""",(R2-P3))"
Range("R3").AutoFill Destination:=Range("R3:R50"), Type:=xlFillDefault
End Sub

HTH,
Bernie
MS Excel MVP


"Pank" wrote in message
...
I recorded a macro that inserts the following formula in cell R2:-

Range("R2").Select
ActiveCell.Formula = "=IF(ISBLANK(P2),"""",1000-P2)"

I then wanted to insert another formula in R3 and the macro recorded it as
:-

Range("R3").Select
ActiveCell.Formula = "=IF(ISBLANK(P3),"""",(R2-P3))"

However when the macro has completed, and I look in cell R3 the formula
reads:-

=IF(ISBLANK(P3),"",1000-P3)

It should say =IF(ISBLANK(P3),"",(R2-P3))

What do I need to change in the macro so that the formula is as I want?

Please also note the next step in the macro is to FILL the formula from
cell
R3 to R50 using:-

Selection.AutoFill Destination:=Range("R2:R50"), Type:=xlFillDefault

Any help offered will be appreciated.




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
Iserror not working as expected NathanG Excel Worksheet Functions 5 February 1st 07 05:31 PM
=NETWORKDAYS not working as expected and as it once did USAOz Excel Worksheet Functions 2 July 13th 06 03:02 PM
Lookup Not working as expected trumpy81 New Users to Excel 5 June 30th 05 07:41 PM
Hyperlink Function not working as expected Hari Prasadh Excel Discussion (Misc queries) 2 April 16th 05 01:23 PM
Application.Volatile not working as expected Richards Excel Discussion (Misc queries) 3 February 3rd 05 12:20 AM


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