![]() |
|
#1
|
|||
|
|||
|
a b d c a
a f g e a c g b f c I will have a table with many letters in it like the one above but with more letters in it. I need a way to type in a letter. If the letter matches one or more cells, I need to highlight each cell that contains the letter. If the letter I type in is a, all of the cells that contain the letter a would turn a certain color, like red or blue. In some of the cells, there might be one or more letters separated by a comma. The sell would light up if the letter a for example was anywhere in the cell. For example, If a cell contained just a, it would highlight. If it contained (a,b,c) it would highlight. What the table represents is the neck of a pedal steel guitar. The excel formula is to find every fret where a certain note occurs. I included that to give an idea of what I am trying to accomplish. Thanks Jimmy |
|
#2
|
|||
|
|||
|
.
. Using this code in a routine module : Code:
Option Explicit
Sub FindAll()
'PURPOSE: Find all cells containing a specified values
'SOURCE: www.TheSpreadsheetGuru.com
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
Dim TextBox1 As TextBox
'What value do you want to find (must be in string form)?
fnd = Sheets("Sheet1").TextBox1.Value '<--- specify which sheet here
Set myRange = ActiveSheet.UsedRange
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
'Test to see if anything was found
If Not FoundCell Is Nothing Then
FirstFound = FoundCell.Address
Else
GoTo NothingFound
End If
Set rng = FoundCell
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd value
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set rng = Union(rng, FoundCell)
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Select Cells Containing Find Value
rng.Select
Exit Sub
'Error Handler
NothingFound:
MsgBox "No values were found in this worksheet"
End Sub
Sub HighlightFindValues()
'PURPOSE: Highlight all cells containing a specified values
'SOURCE: www.TheSpreadsheetGuru.com
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
Dim TextBox1 As TextBox
'What value do you want to find (must be in string form)?
fnd = Sheets("Sheet1").TextBox1.Value
Set myRange = ActiveSheet.UsedRange
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
'Test to see if anything was found
If Not FoundCell Is Nothing Then
FirstFound = FoundCell.Address
Else
GoTo NothingFound
End If
Set rng = FoundCell
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd value
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set rng = Union(rng, FoundCell)
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Highlight Found cells yellow
rng.Interior.Color = RGB(255, 255, 0)
Exit Sub
'Error Handler
NothingFound:
MsgBox "No values were found in this worksheet"
End Sub
|
|
| Tags |
| cell color, if then, what if |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VBA Word - Find Specific Table - Prepend & Append Data to Each Cell | jc491 | Word VBA | 3 | 12-02-2015 09:48 PM |
VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color
|
jc491 | Word VBA | 8 | 09-30-2015 06:10 AM |
use existing table data and not get generic excel chart data
|
canar | Word Tables | 3 | 09-08-2015 03:36 PM |
Importing Data from Excel - Format of table messed up in Word Table
|
epsulliv | Word Tables | 6 | 08-24-2015 07:29 AM |
| find 2 values i a table to find the right prise | Vibov | Excel | 1 | 01-11-2015 07:25 AM |