Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2017, 03:53 PM
curbsidejimmy curbsidejimmy is offline Quetion if then to find data in a table Windows 7 64bit Quetion if then to find data in a table Office 2007
Novice
Quetion if then to find data in a table
 
Join Date: Jan 2017
Posts: 1
curbsidejimmy is on a distinguished road
Default Quetion if then to find data in a table

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
Reply With Quote
  #2  
Old 01-07-2017, 04:31 PM
Logit Logit is offline Quetion if then to find data in a table Windows 10 Quetion if then to find data in a table Office 2007
Expert
 
Join Date: Jan 2017
Posts: 533
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
.
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
Attached Files
File Type: xlsm Find Search Value.xlsm (22.8 KB, 11 views)
Reply With Quote
Reply

Tags
cell color, if then, what if



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
Quetion if then to find data in a table 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
Quetion if then to find data in a table use existing table data and not get generic excel chart data canar Word Tables 3 09-08-2015 03:36 PM
Quetion if then to find data in a table 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft