Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Problems with VBA macro for creating named ranges - ARRRG!

Okay, this is my first post to this group, so I will try to be as complete
and precise as I can. Here's the VBA code as it is written...

Sub Named_Range_Test()
'
' Named_Range_Test Macro
' Macro recorded 2/29/2004 by (name removed)
'
Dim RangeName As String
RangeName = ActiveSheet.Name
Range("D13").Activate
ActiveWorkbook.Names.Add Name:=RangeName, RefersToR1C1:= _
"='" & RangeName & "'!RC:R[956]C[6]"
Range("A14").Activate
End Sub

Okay, now. That macro creates a named range from cell D13 to J969 inclusive
and assigns the sheet's name to this range. No big deal right? Go ahead and
try it. It'll work just fine the first time.

Let's say you have a sheet named "Test1". You run this macro and, low and
behold, there's a named range called "Test1" in your drop-down list up in
the top left corner of the spreadsheet (works as it should). Well, that's
just fine and dandy... except... Click on cell D13 and then select the named
range from the drop-down. Looks fine, right? Great. Now select cell A1 and
choose the named range from the drop-down list again... see what I mean? For
some reason, the named range has been completely redefined using the
relative references that were written in the macro, this time based on cell
A1. (But the macro wasn't re-run was it?) Try choosing cell B9 and select
from the drop-down again. See? What the ???? Any clues? How do I write the
code using absolute references?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Problems with VBA macro for creating named ranges - ARRRG!

Hi Excelguru,

Sub Named_Range_Test()
range("d13:j969").name = activesheet.name
End Sub


Wolf

-----Original Message-----
Okay, this is my first post to this group, so I will try

to be as complete
and precise as I can. Here's the VBA code as it is

written...

Sub Named_Range_Test()
'
' Named_Range_Test Macro
' Macro recorded 2/29/2004 by (name removed)
'
Dim RangeName As String
RangeName = ActiveSheet.Name
Range("D13").Activate
ActiveWorkbook.Names.Add Name:=RangeName,

RefersToR1C1:= _
"='" & RangeName & "'!RC:R[956]C[6]"
Range("A14").Activate
End Sub

Okay, now. That macro creates a named range from cell

D13 to J969 inclusive
and assigns the sheet's name to this range. No big deal

right? Go ahead and
try it. It'll work just fine the first time.

Let's say you have a sheet named "Test1". You run this

macro and, low and
behold, there's a named range called "Test1" in your

drop-down list up in
the top left corner of the spreadsheet (works as it

should). Well, that's
just fine and dandy... except... Click on cell D13 and

then select the named
range from the drop-down. Looks fine, right? Great. Now

select cell A1 and
choose the named range from the drop-down list again...

see what I mean? For
some reason, the named range has been completely

redefined using the
relative references that were written in the macro, this

time based on cell
A1. (But the macro wasn't re-run was it?) Try choosing

cell B9 and select
from the drop-down again. See? What the ???? Any clues?

How do I write the
code using absolute references?


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Problems with VBA macro for creating named ranges - ARRRG!

Well, I'll be damned...

Thanks!

"Wolf" wrote in message
...
Hi Excelguru,

Sub Named_Range_Test()
range("d13:j969").name = activesheet.name
End Sub


Wolf

-----Original Message-----
Okay, this is my first post to this group, so I will try

to be as complete
and precise as I can. Here's the VBA code as it is

written...

Sub Named_Range_Test()
'
' Named_Range_Test Macro
' Macro recorded 2/29/2004 by (name removed)
'
Dim RangeName As String
RangeName = ActiveSheet.Name
Range("D13").Activate
ActiveWorkbook.Names.Add Name:=RangeName,

RefersToR1C1:= _
"='" & RangeName & "'!RC:R[956]C[6]"
Range("A14").Activate
End Sub

Okay, now. That macro creates a named range from cell

D13 to J969 inclusive
and assigns the sheet's name to this range. No big deal

right? Go ahead and
try it. It'll work just fine the first time.

Let's say you have a sheet named "Test1". You run this

macro and, low and
behold, there's a named range called "Test1" in your

drop-down list up in
the top left corner of the spreadsheet (works as it

should). Well, that's
just fine and dandy... except... Click on cell D13 and

then select the named
range from the drop-down. Looks fine, right? Great. Now

select cell A1 and
choose the named range from the drop-down list again...

see what I mean? For
some reason, the named range has been completely

redefined using the
relative references that were written in the macro, this

time based on cell
A1. (But the macro wasn't re-run was it?) Try choosing

cell B9 and select
from the drop-down again. See? What the ???? Any clues?

How do I write the
code using absolute references?


.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Problems with VBA macro for creating named ranges - ARRRG!

Or this one.

Sub testname()
[D13:J969].Name = "RangeName"
End Sub

Regards Robert

"excelguru" wrote in message ...
Well, I'll be damned...

Thanks!

"Wolf" wrote in message
...
Hi Excelguru,

Sub Named_Range_Test()
range("d13:j969").name = activesheet.name
End Sub


Wolf

-----Original Message-----
Okay, this is my first post to this group, so I will try

to be as complete
and precise as I can. Here's the VBA code as it is

written...

Sub Named_Range_Test()
'
' Named_Range_Test Macro
' Macro recorded 2/29/2004 by (name removed)
'
Dim RangeName As String
RangeName = ActiveSheet.Name
Range("D13").Activate
ActiveWorkbook.Names.Add Name:=RangeName,

RefersToR1C1:= _
"='" & RangeName & "'!RC:R[956]C[6]"
Range("A14").Activate
End Sub

Okay, now. That macro creates a named range from cell

D13 to J969 inclusive
and assigns the sheet's name to this range. No big deal

right? Go ahead and
try it. It'll work just fine the first time.

Let's say you have a sheet named "Test1". You run this

macro and, low and
behold, there's a named range called "Test1" in your

drop-down list up in
the top left corner of the spreadsheet (works as it

should). Well, that's
just fine and dandy... except... Click on cell D13 and

then select the named
range from the drop-down. Looks fine, right? Great. Now

select cell A1 and
choose the named range from the drop-down list again...

see what I mean? For
some reason, the named range has been completely

redefined using the
relative references that were written in the macro, this

time based on cell
A1. (But the macro wasn't re-run was it?) Try choosing

cell B9 and select
from the drop-down again. See? What the ???? Any clues?

How do I write the
code using absolute references?


.





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem creating named ranges in a Macro! LABKHAND Excel Discussion (Misc queries) 2 January 8th 10 04:58 PM
Creating dynamic ranges which are named. U0107 Excel Worksheet Functions 1 January 5th 10 11:46 PM
Macro (Print) - Calling Named Ranges KGlennC Excel Discussion (Misc queries) 1 March 19th 05 09:20 PM
Creating dymnamic named ranges John Baker Excel Programming 6 December 4th 03 02:05 PM
Creating Named Ranges in VBA Mark D'Agosta Excel Programming 4 October 4th 03 06:15 AM


All times are GMT +1. The time now is 12:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"