+ Reply to Thread
Results 1 to 4 of 4

Find/Replace Values With X

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2005
    Posts
    11

    Talking Find/Replace Values With X

    Hi all,

    I've got a piece of code I'm stuck on. Basically, I have a range of data and most cells are empty. However, I want to replace all the nonblank cells with an X. I can't quite figure out how to have the code replace something non-specific...

    Here's what I've got - right now, it can find nonblanks, and color them red
    Sub test()
    
    Dim Rng As Range, Cl As Range
    Set Rng = Range("e4:o17")
    For Each Cl In Rng
      
      If Cl <> "" Then
           With Cl.Font
               .Strikethrough = True
               .ColorIndex = 3
           End With
       End If
    
    Next Cl
    End Sub
    Here's the one that has a piece of the replace code, that doesn't work:
    Sub test2()
    
    Dim Rng As Range, Cl As Range
    Set Rng = Range("e4:o17")
    For Each Cl In Rng
      
      If Cl <> "" Then
          
          C1.Replace What:=C1, Replacement:="X", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
          
       End If
    
    Next Cl
    End Sub
    Basically, how do I get the code to just place whatever the number is with an X? I'd appreciate any help - thanks!
    Last edited by delecto; 06-08-2009 at 04:26 PM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Find/Replace Values With X

    delecto,

    Please post your workbook (or a sample) - scroll down and see "Manage Attachments".
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Find/Replace Values With X

    delecto,

    Try:

    
    Option Explicit
    Sub test()
    Dim c As Range
    For Each c In Range("E4:O17")
      If c <> "" Then
        c = "X"
      End If
    Next c
    End Sub

  4. #4
    Registered User
    Join Date
    03-31-2005
    Posts
    11

    Re: Find/Replace Values With X

    Stan,

    Thank you! That's just perfect and it worked great. I can't believe how simple it ended up being...

    Thanks!
    Jill

+ 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