Dividing changing range by value in VBA

Eclektics

New Member
Joined
Jun 9, 2015
Messages
24
Hi all,

I've been really stuck with the below so I'm hoping someone can save the day for me. I'm trying to divide the last value in each column by a figure stored as an integer but I keep getting a run time 1004 error, method 'range of object'_Global' failed and I can't seem to figure it out.

Code:
With rng
            .Formula = "=(" & Range(Cells(LRow, 2)).Address(False, False) & "/" & TotQ & "*(1-(" & Range(Cells(LRow, 2)).Address(False, False) & "/" & TotQ & "))"
        End With

The setting of the 'rng' is fine and works and this is part of a 'With' statement that has defined what worksheet I'm working on but when I attempt to write a formula in the range I get the error. I have similar formulas to the above that are working so I'm not sure why this doesn't. What I'm hoping to see is a formula that looks like '=(B42/40)*(1-(B42/40))'. If anyone can provide assistance I would be really grateful.

Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try :
Code:
With rng
    .Formula = "=(" & Cells(LRow, 2).Address(False, False) & "/" & TotQ & "[COLOR=#ff0000])[/COLOR]*(1-(" & Cells(LRow, 2).Address(False, False) & "/" & TotQ & "))"
End With
 
Upvote 0
It worked!! Can you advise why it didn't need range in the formula? Thanks very much for your help :)
 
Last edited:
Upvote 0
Range (Cells(LRow, 2)) is incorrect syntax.

It should be either Cells(LRow, 2) or ​Range("B" & LRow)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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