+ Reply to Thread
Results 1 to 4 of 4

Find and Replace text

Hybrid View

ferrari2005 Find and Replace text 10-04-2006, 07:20 AM
Bryan Hessey A quick run of 'record macro'... 10-04-2006, 07:52 AM
goose Same thing but... 10-04-2006, 12:41 PM
goose Ok nevermind 10-04-2006, 12:55 PM
  1. #1
    Registered User
    Join Date
    10-04-2006
    Posts
    1

    Find and Replace text

    Hi guys,

    First of all I'm not a programmer! I've been using the record macro facilty to create a macro to find and replace text. The code it generates is as follows:

    Cells.Replace What:="ABCDEF", Replacement:="GHIJKL", _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
    False, ReplaceFormat:=False

    I'm looking to run this code in column A only. However, it looks like if the search string exists in another column, the other column changes but not Column A.

    How would I limit the code to a specific column or is there better coding for what I'm after?

    Cheers
    Roy

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by ferrari2005
    Hi guys,

    First of all I'm not a programmer! I've been using the record macro facilty to create a macro to find and replace text. The code it generates is as follows:

    Cells.Replace What:="ABCDEF", Replacement:="GHIJKL", _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
    False, ReplaceFormat:=False

    I'm looking to run this code in column A only. However, it looks like if the search string exists in another column, the other column changes but not Column A.

    How would I limit the code to a specific column or is there better coding for what I'm after?

    Cheers
    Roy
    A quick run of 'record macro' (one of my favourites too) shows
        Columns("A:A").Select
        Selection.Replace What:="dot", Replacement:="comma", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    suggests you use 'selection' after selecting "A:A"

    Does this help?
    ---

  3. #3
    Registered User
    Join Date
    01-17-2006
    Posts
    9

    Same thing but...

    I was just doing the same thing... using the "Selection" as was previously suggested works.

    I have a similar question though - is there a way to change what is being found/replaced without doing a separate Replace All for each value?

    Either by having a variable or a cell location instead of what's in quotes...
    Replace What:="ABCDEF", Replacement:="GHIJKL"

    I tried just taking out the values in quotes and using the names of my variables, but that didn't seem to work... any ideas?

  4. #4
    Registered User
    Join Date
    01-17-2006
    Posts
    9

    Ok nevermind

    Oops, guess I forgot I had a formula in the cells I was trying to replace, now it works...

    keyval = ActiveCell.Value
    keycode = ActiveCell.Offset(0, 1).Value
    Range("S1:S100").Select
    Selection.Replace What:=keyval, Replacement:=keycode, LookAt:=xlWhole, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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