Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Problem with Macro Calculation

I've got the following macro and instead of dividing by 8 I would like to
divide by Sheet1!$D$22 and then multiply by 52. However when I put that in
place of the 8 I get a run time error. What am I missing?

-- For Each Sh In Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6",
"Sheet7", "Sheet8")
For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52"
Next
Next
End Sub

Thanks.

Bob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Problem with Macro Calculation

You were missing a parethesis at the end. You also need R1C1 format for all
references to other cells.

Worksheets(Sh).Range("W:X").FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"


"Bob" wrote:

I've got the following macro and instead of dividing by 8 I would like to
divide by Sheet1!$D$22 and then multiply by 52. However when I put that in
place of the 8 I get a run time error. What am I missing?

-- For Each Sh In Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6",
"Sheet7", "Sheet8")
For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52"
Next
Next
End Sub

Thanks.

Bob

  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Problem with Macro Calculation

Thanks Joel. That works perfectly. Just for my future reference does the "4"
in R22C4 indicate column "D"?


--
Bob


"Joel" wrote:

You were missing a parethesis at the end. You also need R1C1 format for all
references to other cells.

Worksheets(Sh).Range("W:X").FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"


"Bob" wrote:

I've got the following macro and instead of dividing by 8 I would like to
divide by Sheet1!$D$22 and then multiply by 52. However when I put that in
place of the 8 I get a run time error. What am I missing?

-- For Each Sh In Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6",
"Sheet7", "Sheet8")
For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52"
Next
Next
End Sub

Thanks.

Bob

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem with Macro Calculation

I think that "W" & X was really an address of a single cell in column W.

W7, W8, ..., W500

I don't think that the OP wanted to fill all of W:X with that formula 494 times.

Worksheets(Sh).Range("W" & X).FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"


To the OP:

You could also fill the entire range and drop the loop:

For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52)"
Next X

Becomes:
worksheets(Sh).range("W7").resize(494, 1).formulaR1C1 _
= "=((RC[-19]+RC[-18])/8*52)"



Joel wrote:

You were missing a parethesis at the end. You also need R1C1 format for all
references to other cells.

Worksheets(Sh).Range("W:X").FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"

"Bob" wrote:

I've got the following macro and instead of dividing by 8 I would like to
divide by Sheet1!$D$22 and then multiply by 52. However when I put that in
place of the 8 I get a run time error. What am I missing?

-- For Each Sh In Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6",
"Sheet7", "Sheet8")
For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52"
Next
Next
End Sub

Thanks.

Bob


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem with Macro Calculation

Those last two formulas should have been Joel's version. (I copied pasted from
the wrong line.)



Dave Peterson wrote:

I think that "W" & X was really an address of a single cell in column W.

W7, W8, ..., W500

I don't think that the OP wanted to fill all of W:X with that formula 494 times.

Worksheets(Sh).Range("W" & X).FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"

To the OP:

You could also fill the entire range and drop the loop:

For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52)"
Next X

Becomes:
worksheets(Sh).range("W7").resize(494, 1).formulaR1C1 _
= "=((RC[-19]+RC[-18])/8*52)"

Joel wrote:

You were missing a parethesis at the end. You also need R1C1 format for all
references to other cells.

Worksheets(Sh).Range("W:X").FormulaR1C1 = _
"=((RC[-19]+RC[-18])/Sheet1!R22C4*52)"

"Bob" wrote:

I've got the following macro and instead of dividing by 8 I would like to
divide by Sheet1!$D$22 and then multiply by 52. However when I put that in
place of the 8 I get a run time error. What am I missing?

-- For Each Sh In Array("Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6",
"Sheet7", "Sheet8")
For X = 7 To 500
Worksheets(Sh).Range("W" & X).FormulaR1C1 = "=((RC[-19]+RC[-18])/8*52"
Next
Next
End Sub

Thanks.

Bob


--

Dave Peterson


--

Dave Peterson
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
Calculation Problem djm123 Excel Discussion (Misc queries) 2 January 19th 10 08:54 PM
Calculation problem? dave Excel Discussion (Misc queries) 5 October 14th 05 09:21 AM
Calculation problem Jac Tremblay[_4_] Excel Programming 2 September 26th 05 07:41 PM
Calculation Problem cvolkert Excel Discussion (Misc queries) 0 August 22nd 05 06:14 PM
Macro Ceiling & Floor Calculation Problem... Kevin Lyons Excel Programming 6 December 19th 03 04:56 PM


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