Need a macro that will find and highlight certain cells

Pandrade

New Member
Joined
Apr 13, 2020
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hello,
I need a VBA macro that will find and highlight cells in the salary columns that have values less than 10,000 and find and highlight values in the quantity columns that are more than 100 or less than 1. Can someone help me with this? The columns look like this but there are more than a thousand columns:
1586981932021.png
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I need a VBA macro that will look through the columns automatically because I have about 2,000 columns.
 
Upvote 0
The difficulty with this is that the salary and quantity columns alternate and there are thousands of columns.
 
Upvote 0
Try this code in a copy of your workbook as VBA doesn't have Undo option and I am a beginner in VBA.

VBA Code:
Sub highlightrecords()
Dim lastrow As Long

lastrow = Cells.Find(What:="*", _
            After:=Range("A1"), _
            LookAt:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row

Selection.AutoFilter
Range("A1").EntireRow.Find("Salary").Select
Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:="<10000"
Range(ActiveCell.Offset(1), Cells(lastrow, ActiveCell.Column)).Interior.Color = rgbGreen

Selection.AutoFilter
Range("A1").EntireRow.Find("Quantity").Select
Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:=">100", Operator:=xlOr, Criteria2:="<1"
Range(ActiveCell.Offset(1), Cells(lastrow, ActiveCell.Column)).Interior.Color = rgbGreen

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,381
Messages
6,119,192
Members
448,874
Latest member
Lancelots

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