find and select based on cell value and font color

prasz

New Member
Joined
Sep 12, 2022
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
  2. MacOS
Hi, I need a button to search in excel sheet A column based on value and the value font color and select the first match.
Example:

A column
Test
Test

Any other
Other
Test
Any
Any
Other
Test

I need to find scroll to it and select the first Test value, where the font color is the default black color
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
maybe
VBA Code:
Dim Lrow As Long
Dim i As Integer

On Error GoTo errHandler
Application.EnableEvents = False 'in case there is selectionchange event code that could interfere
Lrow = Range("A" & Rows.count).End(xlUp).Row
For i = 1 To Lrow
     If Range("A" & i).Value = "Test" And Range("A" & i).Font.Color = 0 Then
          Range("A" & i).Select
          Exit Sub
     End If
Next
exitHere:
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere
I don't exactly know if 0 is the default value or not. That code would find the first cell in A that satisfies the parameters regardless of which is the selected cell, which is basically what you asked for. I'm also assuming that the button is on the sheet you're looking in.
 
Upvote 0
Solution
maybe
VBA Code:
Dim Lrow As Long
Dim i As Integer

On Error GoTo errHandler
Application.EnableEvents = False 'in case there is selectionchange event code that could interfere
Lrow = Range("A" & Rows.count).End(xlUp).Row
For i = 1 To Lrow
     If Range("A" & i).Value = "Test" And Range("A" & i).Font.Color = 0 Then
          Range("A" & i).Select
          Exit Sub
     End If
Next
exitHere:
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere
I don't exactly know if 0 is the default value or not. That code would find the first cell in A that satisfies the parameters regardless of which is the selected cell, which is basically what you asked for. I'm also assuming that the button is on the sheet you're looking in.
Thank you verry mutch works like a charm. Have a nice day
 
Upvote 0
If you consider that the solution, maybe mark your thread as solved?
Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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