Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Replacing Sheet references within formulas with VB

Matt,

This is written with an activecell dependency: easy to re-write to do a variable line / range based
on other code (which you didn't post, so.....)

Dim myOldSheetName As String
Dim myNewSheetName As String

myOldSheetName = "XYZ"
myNewSheetName = "X Y Z"

If InStr(1, ActiveCell.Formula, "'" & myOldSheetName & "'") 0 Then
ActiveCell.EntireRow.Replace What:="'" & myOldSheetName & "'", _
Replacement:="'" & myNewSheetName & "'", _
LookAt:=xlPart
Else
ActiveCell.EntireRow.Replace What:=myOldSheetName, _
Replacement:="'" & myNewSheetName & "'", _
LookAt:=xlPart
End If


HTH,
Bernie
MS Excel MVP


"VBMatt" wrote in message
...
Hi,
I'm fairly new to VB and I have a worksheet which creates a summary of
information held on other worksheets.

I'm trying to write a Macro to take a user allocated name, add sheets into
the workbook and then add a line to the summary sheet with the references to
the correct sheet.

I have done the add sheet/add row/copy+paste info from row below, now I need
to replace the old sheet name in the formula with the new sheet name.

Any ideas how to do this as some of the sheets have spaces with the
reference 'X Y Z' and some don't, with the reference XYZ.

Open to suggestions on a better way to do this as well!

Cheers



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
Changing sheet references in formulas Robbyn Excel Programming 9 December 19th 05 07:35 PM
Replacing references from one file to another ewan7279 Excel Programming 2 September 26th 05 11:56 AM
See code enclosed - Convert to formulas with absolute reference inculding the sheet references! Maria J-son Excel Programming 0 May 10th 05 08:40 AM
replacing just the sheet names within formulas Jeanne Criez Excel Worksheet Functions 1 January 4th 05 06:27 PM
Replacing Named Range Names By Cell References in Formulas KL[_6_] Excel Programming 2 December 13th 04 08:56 PM


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