Macro/VBA Help: Need to highlight cells that do not contain specific texts

jodeeeh

New Member
Joined
Jan 8, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi everyone. I am super new in doing macros/VBA codes. I just want to ask about this project that I want to develop.
We currently have a macro that automatically generates the names of files in a specific folder. However I wanted to add something like a "cross-checking" power in which those filenames should contain specific texts/words that are available on a list in a separate spreadsheet. And if they do not contain such texts/words, they would be marked red or highlighted.

Hope I was able to explain the situation clearly! Really really need your help on this. Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hey there!

First, check the image below to see the two sheets I used in this example, but you can change the code to your references

VBA Code:
Sub check_file_names()
    
    Dim x As Integer            'variable used to loop through cells
    Dim y As Integer            'variable used to loop through cells
    Dim file_name As String     'variable to store each file name
    Dim condition As String     'variable to store each condition
    
    'This part will do a loop through each cell in column A, to check your conditions
    
    For x = 1 To Sheets("Imported_files").Range("A5000").End(xlUp).Row     'put the name of your sheet your file names were imported
        
        file_name = Sheets("Imported_files").Range("A" & x).Value
        
        'Now, for each file name, do a loop through each item on your conditions list
        For y = 1 To Sheets("Conditions").Range("A5000").End(xlUp).Row
            
            condition = Sheets("Conditions").Range("A" & y)
            
            If InStr(1, file_name, condition) > 0 Then
                Sheets("Imported_files").Range("A" & x).Interior.Pattern = xlSolid
                Sheets("Imported_files").Range("A" & x).Interior.Color = 255    '255 is the color red
            End If
        
        Next y
  
    Next x
    
    '### PS. I am assuming your files names are in column A, and your conditions are also in column A ###
End Sub


I hope this can help you :)
 

Attachments

  • image_1.png
    image_1.png
    15.9 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,292
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top