Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Creating a named range

Hi all,

i am using the following function to
1) Create a named range
2) return the name of that range

i am having a problem with the line:

ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr

the error is:
Run-time error '1004':
The name is not valid

Public Function GetPageRange(m As String, p As String, c As Integer,
Optional t As String) As String
With Sheets(p)
Dim rng As Range, rng1 As Range, rng2 As Range, sAddr As String,
sName As String
Set rng = Columns(c).Find(m)
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(c).FindNext(rng)
Loop While rng.Address < sAddr
End If
Set rng2 = Range("B3")
Do
Set rng2 = rng2.Offset(0, 1)
Loop While rng2.Value < ""
On Error Resume Next
ActiveWorkbook.names(p & "_" & t).Delete
On Error GoTo 0
sName = p & "_" & t
sAddr = "='" & p & "'!R" & rng.Row & "C2:R" & rng1.Row & "C" &
rng2.Column - 1
ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr
GetPageRange = p & "_" & t
End With
End Function

any thoughts?

tia!

J

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Creating a named range

i use this code i wrote to help me with naming ranges. make a test range on
a sheet and put his on the sheet code page. it will put the syntax in the
immediate window


Sub name_ranges2() ' this creates the named range
Dim nm As Name
sName = ActiveSheet.Name
For Each nm In ThisWorkbook.Names
Debug.Print "ActiveWorkbook.Names.Add Name:=" & """" & nm.Name & """" & _
", Refersto:=""" & "=" & sName & "!" & Range(nm).Address & """"
Next nm
End Sub

--


Gary


"Gixxer_J_97" wrote in message
...
Hi all,

i am using the following function to
1) Create a named range
2) return the name of that range

i am having a problem with the line:

ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr

the error is:
Run-time error '1004':
The name is not valid

Public Function GetPageRange(m As String, p As String, c As Integer,
Optional t As String) As String
With Sheets(p)
Dim rng As Range, rng1 As Range, rng2 As Range, sAddr As String,
sName As String
Set rng = Columns(c).Find(m)
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(c).FindNext(rng)
Loop While rng.Address < sAddr
End If
Set rng2 = Range("B3")
Do
Set rng2 = rng2.Offset(0, 1)
Loop While rng2.Value < ""
On Error Resume Next
ActiveWorkbook.names(p & "_" & t).Delete
On Error GoTo 0
sName = p & "_" & t
sAddr = "='" & p & "'!R" & rng.Row & "C2:R" & rng1.Row & "C" &
rng2.Column - 1
ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr
GetPageRange = p & "_" & t
End With
End Function

any thoughts?

tia!

J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a named range

Using some test values, it worked for me:

set rng = Range("A10")
set rng1 = Range("A20")
set rng2 = Range("F1")
p = "Sheet3"
sAddr = "='" & p & "'!R" & rng.Row & "C2:R" & rng1.Row & "C" &
rng2.Column - 1
? sAddr
='Sheet3'!R10C2:R20C5
sName = "MyName"
ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr
? Range(sName).Address(0,0,xlA1,True)
[Book2]Sheet3!B10:E20

If rng2 is in Column A, you would have a problem.

--
Regards,
Tom Ogilvy



"Gixxer_J_97" wrote in message
...
Hi all,

i am using the following function to
1) Create a named range
2) return the name of that range

i am having a problem with the line:

ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr

the error is:
Run-time error '1004':
The name is not valid

Public Function GetPageRange(m As String, p As String, c As Integer,
Optional t As String) As String
With Sheets(p)
Dim rng As Range, rng1 As Range, rng2 As Range, sAddr As String,
sName As String
Set rng = Columns(c).Find(m)
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(c).FindNext(rng)
Loop While rng.Address < sAddr
End If
Set rng2 = Range("B3")
Do
Set rng2 = rng2.Offset(0, 1)
Loop While rng2.Value < ""
On Error Resume Next
ActiveWorkbook.names(p & "_" & t).Delete
On Error GoTo 0
sName = p & "_" & t
sAddr = "='" & p & "'!R" & rng.Row & "C2:R" & rng1.Row & "C" &
rng2.Column - 1
ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr
GetPageRange = p & "_" & t
End With
End Function

any thoughts?

tia!

J



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a named range


i have this rng:
lngMaxRow = Range("A65536").End(xlUp).Row

Set rng = Union(Range("A3:K" & lngMaxRow), Range("N3:AC"
lngMaxRow)).SpecialCells(xlCellTypeVisible)

i would want to copy the first block a3:k of current sheet into a3:k o
ActiveWorkbook.Sheets(1)

i would want to copy the second block n3:ac of current sheet into n3:a
of ActiveWorkbook.Sheets(1)

i have used this but not work!!!!!!!!:

rng.Copy ActiveWorkbook.Sheets(1).Range("A3"

--
sal2

-----------------------------------------------------------------------
sal21's Profile: http://www.excelforum.com/member.php...nfo&userid=204
View this thread: http://www.excelforum.com/showthread.php?threadid=49160

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Creating a named range

Hmmmm.... Don't know what I did because it's working now and i didn't change
any code.... thanks guys!

J

"Gary Keramidas" wrote:

i use this code i wrote to help me with naming ranges. make a test range on
a sheet and put his on the sheet code page. it will put the syntax in the
immediate window


Sub name_ranges2() ' this creates the named range
Dim nm As Name
sName = ActiveSheet.Name
For Each nm In ThisWorkbook.Names
Debug.Print "ActiveWorkbook.Names.Add Name:=" & """" & nm.Name & """" & _
", Refersto:=""" & "=" & sName & "!" & Range(nm).Address & """"
Next nm
End Sub

--


Gary


"Gixxer_J_97" wrote in message
...
Hi all,

i am using the following function to
1) Create a named range
2) return the name of that range

i am having a problem with the line:

ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr

the error is:
Run-time error '1004':
The name is not valid

Public Function GetPageRange(m As String, p As String, c As Integer,
Optional t As String) As String
With Sheets(p)
Dim rng As Range, rng1 As Range, rng2 As Range, sAddr As String,
sName As String
Set rng = Columns(c).Find(m)
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(c).FindNext(rng)
Loop While rng.Address < sAddr
End If
Set rng2 = Range("B3")
Do
Set rng2 = rng2.Offset(0, 1)
Loop While rng2.Value < ""
On Error Resume Next
ActiveWorkbook.names(p & "_" & t).Delete
On Error GoTo 0
sName = p & "_" & t
sAddr = "='" & p & "'!R" & rng.Row & "C2:R" & rng1.Row & "C" &
rng2.Column - 1
ActiveWorkbook.names.Add name:=sName, RefersToR1C1:=sAddr
GetPageRange = p & "_" & t
End With
End Function

any thoughts?

tia!

J




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
Creating a named range gives an error only when the filename is lo Adi[_2_] Excel Discussion (Misc queries) 1 September 15th 09 01:14 PM
Creating a named range? dksaluki Excel Discussion (Misc queries) 2 February 22nd 08 03:12 AM
Can I use named range in data range box when creating pie chart? BJackson Charts and Charting in Excel 2 August 17th 05 05:37 PM
plz help: creating named range in VBA, loop goes haywire KR Excel Programming 2 April 14th 05 07:25 PM
Creating a Named Range using VB Adriaan van der Linde Excel Programming 4 December 5th 03 01:05 PM


All times are GMT +1. The time now is 03:59 AM.

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

About Us

"It's about Microsoft Excel"