Insert Names Macro

derickc

New Member
Joined
May 28, 2002
Messages
23
I'm trying to create a macro that will insert the column heading as a name for the entire selection in rows 7 through 1310 beneath each column heading (which is in Row6). When trying the following, I get an "invalid name" error message. Any clues? Thank you.


Sub InsertName()
'
' InsertName Macro
' Macro recorded 8/29/2002 by Derick Cooper
'

'

Dim lngCol As Long

For lngCol = 5 To 10
Range(Cells(7, lngCol), Cells(1310, lngCol)).Select
ActiveWorkbook.Names.Add Name:=Cells(6, lngCol).Text, RefersToR1C1:= _
"='Standard Deviations'!R7C[lngCol]:R1310C[lngCol]"

Next lngCol

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The problem is apparently in the following code:

"='Standard Deviations'!R7C[lngCol]:R1310C[lngCol]"
 
Upvote 0
This is the speghetti theory of coding. I just keep changing things til something works. I changed to from the R1C1 reference style to this: RefersTo:= "='Standard Deviations'!Range(Cells(7,lngCol), Cells(1310, lngCol))"

Which has apparently worked. When I look under names/define all my new names are there, but when I try to "Goto" one of the new names it isn't recognized.

Any clues?

-dc
 
Upvote 0
change:

"='Standard Deviations'!R7C[lngCol]:R1310C[lngCol]"

to:

"='Standard Deviations'!R7C" & lngCol & ":R1310C" & lngCol
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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