+ Reply to Thread
Results 1 to 3 of 3

a macro to check cell values against other cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    04-22-2011
    Location
    nj
    MS-Off Ver
    Excel 2010
    Posts
    24

    a macro to check cell values against other cell values

    I dont know if this is possible but i wanted to see if there was a way to check to see if any of the text in the range J3:Y47 is ONE letter off from any other cell in tht range. like if a cell was "dog" and another cell was "do" then there would be some type of error message or highlight the cell or something

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: a macro to check cell values against other cell values

    Perhaps something like this?

    Sub FindOneLetterOff()
        Dim nRow As Long, nCol As Long, str As String, sFirstAddress As String
        Dim rg As Range, rgFind As Range
        'Set Range to Search
        Set rg = Range("$J$3:$Y$47")
        With rg
            For nCol = 1 To .Columns.Count
                For nRow = 1 To .Rows.Count
                str = .Cells(nRow, nCol)
                'Chop last character off of string
                If Len(str) > 1 Then str = Left$(str, Len(str) - 1)
                    Set rgFind = .Find(What:=str, Lookat:=xlWhole, After:=rg.Cells(1, 1))
                    If Not rgFind Is Nothing Then
                        sFirstAddress = rgFind.Address
                        Do
                            rgFind.Interior.ColorIndex = 3 'Red
                            Set rgFind = .FindNext(rgFind)
                        Loop While Not rgFind Is Nothing And rgFind.Address <> sFirstAddress
                    End If
                Next nRow
            Next nCol
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    04-22-2011
    Location
    nj
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: a macro to check cell values against other cell values

    works perfect! thanks a lot i just couldnt find figure it out for the life of me!

+ 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