Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defined Names


There are thousands of Defined name to be renamed. The prefix of thes
defined names is bb and would like to change the prefix to xxxbb. Thes
defined names are used in formulae. How do I create the macro or vba t
do the job.
Thanks for your help

--
rick
-----------------------------------------------------------------------
rickv's Profile: http://www.excelforum.com/member.php...fo&userid=2594
View this thread: http://www.excelforum.com/showthread.php?threadid=39350

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Defined Names

Hi RickV,

Try:

'===========================
Public Sub Tester()
Dim Nme As Name
Dim sStr As String
Dim strOldName As String
Dim strNewName As String

Const myPrefix As String = "xxx"

For Each Nme In ActiveWorkbook.Names

If Nme.Name Like "bb*" Then
sStr = Nme.RefersTo
strOldName = Nme.Name
strNewName = myPrefix & strOldName
ActiveWorkbook.Names.Add strNewName, RefersTo:=sStr
Nme.Delete
End If

Next Nme

End Sub
'<<=======================


---
Regards,
Norman



"rickv" wrote in
message ...

There are thousands of Defined name to be renamed. The prefix of these
defined names is bb and would like to change the prefix to xxxbb. These
defined names are used in formulae. How do I create the macro or vba to
do the job.
Thanks for your help.


--
rickv
------------------------------------------------------------------------
rickv's Profile:
http://www.excelforum.com/member.php...o&userid=25942
View this thread: http://www.excelforum.com/showthread...hreadid=393501



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Defined Names

Hi RickV,

And if these thousands of old defined names are already in use, you can run
the following sub to correct the formulae and implement the new defined
names.


'===========================
Public Sub Tester02()

Dim SH As Worksheet
Dim Rng As Range
Const strOld As String = "bb"
Const strNew As String = "xxxbb"


For Each SH In ActiveWorkbook.Worksheets
SH.Cells.Replace What:=strOld, _
Replacement:=strNew, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Next SH

End Sub


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi RickV,

Try:

'===========================
Public Sub Tester()
Dim Nme As Name
Dim sStr As String
Dim strOldName As String
Dim strNewName As String

Const myPrefix As String = "xxx"

For Each Nme In ActiveWorkbook.Names

If Nme.Name Like "bb*" Then
sStr = Nme.RefersTo
strOldName = Nme.Name
strNewName = myPrefix & strOldName
ActiveWorkbook.Names.Add strNewName, RefersTo:=sStr
Nme.Delete
End If

Next Nme

End Sub
'<<=======================


---
Regards,
Norman



"rickv" wrote in
message ...

There are thousands of Defined name to be renamed. The prefix of these
defined names is bb and would like to change the prefix to xxxbb. These
defined names are used in formulae. How do I create the macro or vba to
do the job.
Thanks for your help.


--
rickv
------------------------------------------------------------------------
rickv's Profile:
http://www.excelforum.com/member.php...o&userid=25942
View this thread:
http://www.excelforum.com/showthread...hreadid=393501





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Defined Names

Hi RickV,

And if the workbook potentially contained strings comprising the 'bb'
substring, then you might wish to limit the replacement to formulae, e,g,:

'===========================
Public Sub Tester02A()

Dim SH As Worksheet
Dim Rng As Range
Const strOld As String = "bb"
Const strNew As String = "xxxbb"


For Each SH In ActiveWorkbook.Worksheets
Set Rng = Nothing
On Error Resume Next
Set Rng = SH.Cells.SpecialCells(xlFormulas)
On Error GoTo 0

If Not Rng Is Nothing Then
Rng.Replace What:=strOld, _
Replacement:=strNew, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
Next SH

End Sub
'<<===========================

Depending on the workbook's specific data, you may need futher to restrict
the ambit of the Rng variable and, perhaps, limit operation to specified
worksheets.


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi RickV,

And if these thousands of old defined names are already in use, you can
run the following sub to correct the formulae and implement the new
defined names.


'===========================
Public Sub Tester02()

Dim SH As Worksheet
Dim Rng As Range
Const strOld As String = "bb"
Const strNew As String = "xxxbb"


For Each SH In ActiveWorkbook.Worksheets
SH.Cells.Replace What:=strOld, _
Replacement:=strNew, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Next SH

End Sub


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi RickV,

Try:

'===========================
Public Sub Tester()
Dim Nme As Name
Dim sStr As String
Dim strOldName As String
Dim strNewName As String

Const myPrefix As String = "xxx"

For Each Nme In ActiveWorkbook.Names

If Nme.Name Like "bb*" Then
sStr = Nme.RefersTo
strOldName = Nme.Name
strNewName = myPrefix & strOldName
ActiveWorkbook.Names.Add strNewName, RefersTo:=sStr
Nme.Delete
End If

Next Nme

End Sub
'<<=======================


---
Regards,
Norman



"rickv" wrote in
message ...

There are thousands of Defined name to be renamed. The prefix of these
defined names is bb and would like to change the prefix to xxxbb. These
defined names are used in formulae. How do I create the macro or vba to
do the job.
Thanks for your help.


--
rickv
------------------------------------------------------------------------
rickv's Profile:
http://www.excelforum.com/member.php...o&userid=25942
View this thread:
http://www.excelforum.com/showthread...hreadid=393501







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defined Names


Thanks Norman... i will follow your instructions

--
rick
-----------------------------------------------------------------------
rickv's Profile: http://www.excelforum.com/member.php...fo&userid=2594
View this thread: http://www.excelforum.com/showthread.php?threadid=39350



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
Why use defined names? Eric Excel Discussion (Misc queries) 2 December 31st 07 06:07 AM
Defined names lesley1000 via OfficeKB.com Excel Worksheet Functions 3 December 10th 07 02:50 PM
NAMES DEFINED F. Lawrence Kulchar Excel Discussion (Misc queries) 5 November 14th 06 07:54 AM
Defined names DREED Excel Discussion (Misc queries) 3 March 10th 06 02:55 PM
Using defined names in VBA... BeSmart Excel Programming 4 September 24th 04 10:11 AM


All times are GMT +1. The time now is 04:31 AM.

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"