0

I am attempting to create a macro that creates X amount of named formulas that use the offset formula. The X will represent the number of data series (columns) that are on sheet1. This is how I want this to look for one of them to be created.

formula = offset($b$2,$a$2,0,$a$3,1)
activeworkbook.names.add Name:="test", Refers to:=formula

But I'm going to use a do loop until i = # of columns with values. So this is my best shot at this, and i'm sure there are plenty of errors because i can't make it run:

columns = activesheet.countif((1:1),"*"
i = 5 
do until i = columns

'This is where i want to define my static cells location (not value) to be referenced in the formula
    pan = cells(1,2)
    zoom = cells(1,3)

'This is where i want to define my dynamic cells location (not value) based on the current column
    series = cells(2,i)

'This is where i want to create a name formulas specific to each series
    formula = "=offset(" & series & "," & pan & ",0" & zoom & ",1)
    activeworkbook.names.add name:=cells(1,i), refersto:=formula

So my results are basically, I get a new name formula but the reference formula is filled with integers and not the actual cell address. This is because I'm using a formula that calls the cell's value rather than pasting the cells address.

Any help would be great.

2
  • 1
    have you tried CELLS.ADDRESS ?
    – user2140173
    Mar 14, 2013 at 9:28
  • could you please give some idea what you have in Cells(2,i)? just any expample... Mar 14, 2013 at 10:00

1 Answer 1

0

Ok, I figured out what i was doing wrong. When i recorded the macro, i didn't realize that it put

ActiveWorkbook.Names.Add Name:="Height___zoom", RefersToR1C1:="=Data!R5C1"

Now I can simply make the do lop with the

columns = activesheet.countif((1:1),"*"
i = 5 
do until i = columns

pan = "R1C2"
zoom = "R1C3"

series = "R2C" & i

formula = "=offset(" & series & "," & pan & ",0" & zoom & ",1)
activeworkbook.names.add name:=cells(1,i), refersto:=formula

Or something like that. Still gotta work some kinks out to make it actually run correctly, but i found out the formula uses R#C# to refer to the cell's location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.