Need assistance with for loop in vba

ak368

New Member
Joined
Nov 12, 2018
Messages
6
I am unsure how to correct this code in VBA.
Code:
Sub Macro4()
'
' Macro4 Macro
'


'
For i = 2 To 13
Dim Speed As Double
    
    Speed = Cells(i, 9).Value
    Range("C2").Select
    ActiveCell.FormulaR1C1 = _
        "=(R2C13*0.89/Speed)*((RC[-2]*0.89/Speed)^(R2C13-1))*(EXP(-((RC[-2]*0.89/Speed)^R2C13)))"
    A = ActiveCell.Value
    Selection.AutoFill Destination:=Range("C2:C21"), Type:=xlFillDefault
    Cells(i, 10) = "=R22C4"
    B = ActiveCell.Value
    Next i
    
End Sub

The result is debugged in this image below.

http://tinypic.com/r/33usx6s/9

Here is the screenshot of what happens when I click run on the excel file.

http://tinypic.com/r/1495j7s/9

I am new to vba. I don't know why in the first image, there is an Error 2029 displayed when debugging for both the variables. Does this mean that there is something wrong with my formula? How do I correct this.

I'm trying to get the VBA code to run so that the summation in column 4 row 22 is outputted onto each row of column 10 for the monthly kW calculations. Appreciate any help.
 
Yep....
Removed Range("C2").Select line as the formula can be inserted in one large block by replacing with the Range("C2:C21").FormulaR1C1 = line
Removed Selection.AutoFill Destination:=Range("C2:C21"), Type:=xlFillDefault line as it's not required when filling a range with a formula
Removed the A= active cell line as it's redundant
Removed the S=Activecell line as it's redundant
Changed Cells(i, 10) line to accept a value not a formula

Hope that helps...(y)
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,217,985
Messages
6,139,802
Members
450,237
Latest member
uuavjed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top