Consulting

Results 1 to 8 of 8

Thread: Replace only in text and numbers (not in formulas)

  1. #1

    Replace only in text and numbers (not in formulas)

    Hi, i tried search on google, also here in forum, but was not succsessfull.
    I try to find and replace characters - text and numbers in my wb and replace it with other text and numbers. Problem is, that replace looks also in formulas and then it want to replace also in links in path, in formulas and so. But this i dont want.
    Is any possibility to use replace funkcionality only in text, numbers but NOT IN FORMULAS?

    thx a lot.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    perhaps...
    Dim cll As Range
    For Each cll In ActiveSheet.Cells.SpecialCells(xlCellTypeConstants, 23)
        If cll.Hyperlinks.Count = 0 Then cll.Replace "OldVal", "NewVal"
    Next cll
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Yes, this works greate. But only in actual sheet .
    But i have a lot of sheets in my wb. How can i set, that macro do it for all my sheets in WB?
    thx a lot for your help

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Dim ws As Worksheet, cll As Range
    For Each ws In Worksheets
        For Each cll In ws.Cells.SpecialCells(xlCellTypeConstants, 23)
            If cll.Hyperlinks.Count = 0 Then cll.Replace "OldVal", "NewVal"
        Next cll
    Next ws
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    thx a lot, it works

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    or
    Sub tst()
        for each sh in sheets
           sh.Cells.SpecialCells(2).Replace "k", "P"
        next
    End Sub

  7. #7
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    @snb

    that was my first attempt.
    cells containing hyperlinks are also included in the constants.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    @mancubus

    Yes you are right; I tested with formula hyperlinks.

Tags for this Thread

Posting Permissions

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