+ Reply to Thread
Results 1 to 4 of 4

Highlighting a character which is not present in the keyboard

Hybrid View

  1. #1
    Registered User
    Join Date
    05-06-2013
    Location
    bangalore, india
    MS-Off Ver
    Excel 2010
    Posts
    28

    Highlighting a character which is not present in the keyboard

    I want to highlight the specific character which is not present in the keyboard (Special Characters). The below code is highlighting the cell which contains such character but not the character alone. Kindly help!!

    Sub SplChars()
    Dim sCharOK As String, s As String
    Dim r As Range, rc As Range
    Dim j As Long
    
    sCharOK = "1234567890-=~!@#$%^&*()_+qwertyuiop[]\asdfghjkl;'zxcvbnm, ./QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>?"""
    
    Set r = Worksheets("Sheet1").UsedRange.SpecialCells(xlCellTypeConstants, xlTextValues)
    
    ' loop through all the cells with text constant values and paints in yellow the ones with characters not in sCharOK
    For Each rc In r
        s = rc.Value
        For j = 1 To Len(s)
            If InStr(sCharOK, Mid(s, j, 1)) = 0 Then
                rc.Interior.Color = vbYellow
                Exit For
            End If
        Next j
    Next rc
    
    End Sub

  2. #2
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Highlighting a character which is not present in the keyboard

    hi tehre!
    try this way (untested):


    Sub SplChars()
    Dim sCharOK As String, s As String
    Dim r As Range, rc As Range
    Dim j As Long
    
    sCharOK = "1234567890-=~!@#$%^&*()_+qwertyuiop[]\asdfghjkl;'zxcvbnm, ./QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>?"""
    
    Set r = Worksheets("Sheet1").UsedRange.SpecialCells(xlCellTypeConstants, xlTextValues)
    
    ' loop through all the cells with text constant values and paints in yellow the ones with characters not in sCharOK
    For Each rc In r
        s = rc.Value
        For j = 1 To Len(s)
            If InStr(sCharOK, Mid(s, j, 1)) = 0 Then
                rc.Characters(j, 1).Font.Bold = True
                ''rc.Interior.Color = vbYellow
                Exit For
            End If
        Next j
    Next rc
    
    End Sub
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  3. #3
    Registered User
    Join Date
    05-06-2013
    Location
    bangalore, india
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Highlighting a character which is not present in the keyboard

    Hi Bulina2k,

    The code works great. However, it only bolds the first special character. But not all. For example if I have the word "Expanâtio€", only the "â" is highlighted but not "€".

    -Roshan

  4. #4
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Highlighting a character which is not present in the keyboard

    Delete the "Exit For"


    Sub SplChars()
    Dim sCharOK As String, s As String
    Dim r As Range, rc As Range
    Dim j As Long
    
    sCharOK = "1234567890-=~!@#$%^&*()_+qwertyuiop[]\asdfghjkl;'zxcvbnm, ./QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>?"""
    
    Set r = Worksheets("Sheet1").UsedRange.SpecialCells(xlCellTypeConstants, xlTextValues)
    
    ' loop through all the cells with text constant values and paints in yellow the ones with characters not in sCharOK
    For Each rc In r
        s = rc.Value
        For j = 1 To Len(s)
            If InStr(sCharOK, Mid(s, j, 1)) = 0 Then
             
                       rc.Characters(j, 1).Font.Bold = True
    
            End If
        Next j
    Next rc
    
    End Sub

    Alternatively you coud:


    For Each rc In r
        s = rc.Value
        For j = 1 To Len(s)
            If InStr(sCharOK, Mid(s, j, 1)) = 0 Then
                With rc.Characters(j, 1).Font
                    .Bold = True
                    .Size = 16
                    .Color = rgbCadetBlue
                End With
            End If
        Next j
    Next rc
    and so on...



    Please mark SOLVED and Add Reputation if my answer pleases you. Thank you.
    Last edited by bulina2k; 12-15-2015 at 06:05 AM. Reason: completing

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Splitting strings if a character is present within them
    By mfd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2014, 04:25 PM
  2. Formula to Copy/Paste if Certain Character is Present?
    By johnstoll in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-24-2014, 08:13 PM
  3. Highlighting Conditional Character Count
    By bjcowen9000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-19-2013, 10:06 AM
  4. Replies: 5
    Last Post: 06-03-2011, 10:00 AM
  5. If a character is present, then move entire cell to...
    By rgulri in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-15-2008, 02:20 PM
  6. Drop down keyboard character selection
    By stemcell1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2007, 01:42 AM
  7. Replies: 1
    Last Post: 12-05-2005, 06:45 PM

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