+ Reply to Thread
Results 1 to 7 of 7

How to insert Cells VALUE (Search and Replace Macro)

  1. #1
    Registered User
    Join Date
    11-05-2010
    Location
    israel
    MS-Off Ver
    Excel 2003
    Posts
    32

    How to insert Cells VALUE (Search and Replace Macro)

    Hi there guys.

    I have this Search and Replace Macro:

    Public Sub Priority()

    For Each cell In Selection
    cell.Value = Replace(cell.Value, "xxx", "B4.Value")
    Next cell
    End Sub


    As you can see,
    the outcome is that xxx becomes "B4.Value", instead of 0001, which is cells' B4 value.
    note that each day 0001 changes (to 0002 and so on...)

    How can I do the macro to put in real B4.Value and not B4.Value as text?

    Thanks ahead!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to insert Cells VALUE (Search and Replace Macro)

    Repace "B4.Value" with CStr(ActiveSheet.Range("B4").Value)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    11-05-2010
    Location
    israel
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: How to insert Cells VALUE (Search and Replace Macro)

    Thanks, but error.

  4. #4
    Registered User
    Join Date
    11-05-2010
    Location
    israel
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: How to insert Cells VALUE (Search and Replace Macro)

    Sorry, Works!

    But, I cant undo that. Is there a way to fix it?

    By the way,
    I changed the code a bit,

    ActiveCell.Replace What:="xxx", Replacement:=CStr(ActiveSheet.Range("B4").Value), LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False


    Thanks ahead, again...
    Last edited by NatanZ; 11-27-2010 at 02:32 PM.

  5. #5
    Registered User
    Join Date
    11-05-2010
    Location
    israel
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: How to insert Cells VALUE (Search and Replace Macro)

    Bump, please.
    Sorry about the tri-post.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to insert Cells VALUE (Search and Replace Macro)

    The short answer about UNDO is no, you cannot undo the actions of a macro. You can write a macro that will "counter do" the action of another, but how easy that is depends on the actions of the first (e.g if one macro sorts, how is the counter macro to know the existing order before the first sorted, unless the first stores it somewhere......)

    In short, no.

  7. #7
    Registered User
    Join Date
    11-05-2010
    Location
    israel
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: How to insert Cells VALUE (Search and Replace Macro)

    Quote Originally Posted by mikerickson View Post
    The short answer about UNDO is no, you cannot undo the actions of a macro. You can write a macro that will "counter do" the action of another, but how easy that is depends on the actions of the first (e.g if one macro sorts, how is the counter macro to know the existing order before the first sorted, unless the first stores it somewhere......)

    In short, no.
    The important thing is not to undo the macro, but to undo multiple times... I guess not, then.

+ 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