Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find all cells that do not contain specific text

Posted on 2011-09-22
3
Medium Priority
?
212 Views
Last Modified: 2012-05-12
I have a column of data which I need to get the cell address of if it does not contain specific characters in the first 4 characters in the contents.

For example I want to find all cells that does not contain one of the following as the first four characters: {AAA, {DDD, {SSS, {XYZ

Sample data could look like this:

These are ok since they match the criteria - I do not want to find them
{AAA,ABC,CCC,""}  
{SSS,ABC,CCC,""}  
{XYZ,"","",""}  

I want to find these cells since the first 4 characters do not match any of the values I am looking for
{ABC,ABC,CCC,""}  
{ABC,"",AAA,""}  

When I find those cells I want to get the cell information (row) as well as color the cell with red.

I know I can loop through each cell in the column, however, that is pretty slow.

In this example (
Range("A1:D500").SpecialCells(xlCellTypeBlanks) = "Blank"

Open in new window

) I can find blank cells very quickly. However I do not know how to translate that code into something that will achieve the requirement I have.

There may be no other way than to loop through each cell - if so that is what I will do.
0
Comment
Question by:ckelsoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36581493
You could try something like this. Only takes a few seconds even on an entire column of 1m+ rows.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 36581503
Helps if I add the code...
Sub highlights()
   Dim lngLastRow        As Long
   Dim i                 As Long
   Dim strRng            As String
   Dim varData
   Dim strColumn         As String

   ' change to match your column
   strColumn = "A"

   lngLastRow = Cells(Rows.Count, strColumn).End(xlUp).Row

   varData = Range(Cells(1, strColumn), Cells(lngLastRow, strColumn))

   Application.ScreenUpdating = False

   For i = LBound(varData, 1) To UBound(varData, 1)     'change 4 to whatever you want for start row
      'In the next line, change >3 to whatever you like, such as ="Ckid" or
      'whatever string you want, or to =vbnullstring if you want to count/mark blanks
      Select Case Left$(UCase$(varData(i, 1)), 4)
         Case "{AAA", "{DDD", "{SSS", "{XYZ"
            ' do nothing
         Case Else
            strRng = strRng & "," & strColumn & i
            If Len(strRng) > 245 Then
               Range(Right(strRng, Len(strRng) - 1)).Interior.Color = vbRed
               strRng = vbNullString
            End If
      End Select
   Next i
   Range(Right(strRng, Len(strRng) - 1)).Interior.Color = vbRed
   
   Application.ScreenUpdating = True
End Sub

Open in new window


:)
0
 

Author Closing Comment

by:ckelsoe
ID: 36581964
Your code worked perfectly with some adaptions to my sheet. I did not think of using the select case to help solve this problem. Thanks very much.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question