Consulting

Results 1 to 3 of 3

Thread: Solved: Get The Replaced Cell's Address

  1. #1
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location

    Question Solved: Get The Replaced Cell's Address

    Hi everyone ,

    I have a little problem here :

    I use the following code to make replacements in cells using macro :

    [VBA] Cells.Replace What:="Sample Text", Replacement:="Sample Text2", LookAt:=xlPart, SearchOrder _
    :=xlByColumns, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    [/VBA]

    I works fine for me but how to select or get the address of the cell where the replacement has made. Any Idea ??

    Help !


    Best Regards,
    Dan

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim oCell As Range
    Set oCell = Cells.Find("Sample Text")
    If Not oCell Is Nothing Then
    oCell.Value = "Sample Text2"
    MsgBox oCell.Address
    End If
    [/vba]

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Dan
    Split the Replace from the Find

    [VBA]Dim c As Range
    Set c = Cells.Find(What:="Sample Text", _
    LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False, _
    SearchFormat:=False)
    c = "Sample Text2"
    MsgBox c.Address

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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