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

This won't work (either...)

sAddr dosn't get accepted as a cell address...


sAddr = ActiveCell.Address
ActiveWorkbook.Names.Add Name:="test"
RefersToR1C1:="=Lister!R1C7:sAddr

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Naming a range with VBA...

Dim sAddr as String
sAddr = ActiveCell.Address(1,1,xlR1C1)
ActiveWorkbook.Names.Add Name:="test", _
RefersToR1C1:="=Lister!R1C7:" & sAddr

--
Regards,
Tom Ogilvy

"Steff_DK " wrote in message
...
This won't work (either...)

sAddr dosn't get accepted as a cell address...


sAddr = ActiveCell.Address
ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Lister!R1C7:sAddr"


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Naming a range with VBA...

Stef here is a reply i got many months ago from an MVP on this forum.
The code was NOT written by me.


Try something like the following:

If being done from VBA in Excel

Workbooks("Book1.xls").Names.Add Name:="test",
RefersTo:="=sheet1!$a$1:$c$20"

If being done from VBA in any application other than Excel

<ApplicationObject.Workbooks("Book1.xls").Names.A dd Name:="test",
RefersTo:="=sheet1!$a$1:$c$20"

Where <ApplicationObject is the variable that refers to the Excel
Application instance

Easier would be:

rnum = 21
With xlwksht2
.Range("A3:A" & rnum).Name = Name1
End With

Hope this is of help

--
Message posted from http://www.ExcelForum.com

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

Dim sNewname As String
sNewname = ""
Do While sNewname = ""
sNewname = InputBox("Enter initials for new person:")
If sNewname = "" Then iSvar = MsgBox("Do you want to quit?", vbYesNo)
If iSvar = vbYes Then
Exit Do
End If

Loop

Range("C2").CurrentRegion.Select

Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Value = sNewname
Dim sAddr As String
sAddr = ActiveCell.Address

MsgBox sAddr
ActiveWorkbook.Names("ansvar").Delete
ActiveWorkbook.Names.Add Name:="ansvar", RefersTo:="=Lister!$c$1:"
sAddr

Range("C2").CurrentRegion.Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
_
DataOption1:=xlSortNorma

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Naming a range with VBA...

sAddr dosn't get accepted as a cell address...
sAddr = ActiveCell.Address
ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Lister!R1C7:sAddr"


Try:

RefersTo:="=Lister!G1:" & sAddr

Cheers, Pete.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Naming a range with VBA...

Dim sNewname As String
sNewname = ""
Do While sNewname = ""
sNewname = InputBox("Enter initials for new person:")
If sNewname = "" Then iSvar = MsgBox("Do you want to quit?", vbYesNo)
If iSvar = vbYes Then
Exit Do
End If

Loop

Range("C2").CurrentRegion.Select

Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Value = sNewname
Dim sAddr As String
sAddr = ActiveCell.Address

MsgBox sAddr
ActiveWorkbook.Names("ansvar").Delete
ActiveWorkbook.Names.Add Name:="ansvar", RefersTo:="=Lister!$c$1:"
sAddr

Range("C2").CurrentRegion.Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
_
DataOption1:=xlSortNorma

--
Message posted from http://www.ExcelForum.com

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
Naming a range hello Excel Discussion (Misc queries) 3 May 7th 07 07:01 PM
Range naming Squeaky Excel Discussion (Misc queries) 2 December 29th 06 09:10 PM
Naming a range cornishbloke[_5_] Excel Programming 1 December 15th 03 02:28 PM
Range naming BigJim Excel Programming 5 December 2nd 03 01:06 PM
Naming a Range with VB Justin Excel Programming 2 December 1st 03 09:38 PM


All times are GMT +1. The time now is 09:44 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"