Results 1 to 5 of 5

Macro to replace cells value automatically based on another cell change event

Threaded View

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    London
    MS-Off Ver
    Excel 210
    Posts
    5

    Macro to replace cells value automatically based on another cell change event

    I know there are several threads but I wasn't able to find something which will fit my needs.
    I have a sheet in which I want to Find & Replace cell values based on the cell $B1 which will be a drop down list. Also I need to mention that the cells which I want to replace the string have formulas. Here's an example of what a cell looks:
    =IF('http://sharepoint.www.com/Industrial Engineering/2011.06 June/[Workbook.xls]June'!I218=0,"",'http://sharepoint.www.com/Industrial Engineering/2011.06 June/[Workbook.xls]June'!I218)

    By changing the value from $B1 from Workbook to Workbook1 I want to automatically replace in a specific range the values from the cell: Workbook.xls with Workbook1.xls

    I have a code which will work but I need to narrow down the replace function to a specific range like $A2:$BA250

    My macro looks like this:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
      Dim txtW As String
      txtW = Range("$H$13").Value
      Dim txtR As String
      txtR = Range("$B$1").Value
    If Target.Address = "$B$1" Then
    
    Cells.Replace What:=txtW, Replacement:=txtR, LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    
        Else
    Range("$b$1").Select
        End If
    End Sub
    Last edited by phsilverhp; 06-09-2011 at 09:44 AM. Reason: SOLVED

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1