Help needed - using variable ranges in formulas via macro

EllieCat

New Member
Joined
May 9, 2007
Messages
44
Hi There,

I have a macro which is going down a list of data, finding where the relavant sections start and end, and then I need to feed these back into a formula elsewhere.

What I've got (which doesn't work!) is:

Code:
mycell.Formula = "=mode(" & Range(rangestart, rangeend) & ")"

Can anyone spot what I'm doing wrong? Or does anyone know an alternative way to find out the mode for values matching specific criteria?

Thanks!

Ellie-Cat
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Shouldn't that be:
Code:
mycell.Formula = "=mode(" & Range(rangestart, rangeend).Address & ")"
?
 
Upvote 0
Yes, it should be!

Only problem is it's giving me ranges without the sheet info in (i.e. my data and summary tables are on different sheets, and it's giving me the right range on the summary sheet instead of the data sheet)

I can work around by moving them on to a single sheet, but does anyone know how to get it to work across sheets correctly?

Thanks for your help Glenn

EllieCat
 
Upvote 0
In that case, put the sheet name in the formula:
Code:
mycell.Formula = "=mode(Sheet1!" & Range(rangestart, rangeend).Address & ")"
or
Code:
mycell.Formula = "=mode('Another sheet'!" & Range(rangestart, rangeend).Address & ")"
 
Upvote 0
Alternatly, your formula could refer to a named range.
Code:
myCell.Formual = "=MODE(myNamedRange)"

And your updating code would define that name, rather than changing a formula
Code:
Range(rangeStart, rangeStop).Name = "myNamedRange"
 
Upvote 0
Alternatly, your formula could refer to a named range.
Code:
myCell.Formual = "=MODE(myNamedRange)"

And your updating code would define that name, rather than changing a formula
Code:
Range(rangeStart, rangeStop).Name = "myNamedRange"
many ways to skin that cat :)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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