Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Searching for a string and then shading the row

Being new to VBA programming, I'm struggling to put together a macro that
will accomplish the following:

1. Search the cells in a specific column (H) - starting at row 3 - for the
presence of a particular word from a list of 3 different words.

2. If one of the words is found, the entire row (from columns A through H)
would be shaded.

3. The search would continue through the rest of the cells in the column
with the same action being repeated to the end of the column.

All help would be appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Searching for a string and then shading the row

Greg,

Here's one way to do it:

Sub test()
Dim rng As Range
Dim c As Range
Dim vWords As Variant

vWords = Array("One", "Two", "Three")

Set rng = Range(Range("H3"), Range("H65535").End(xlUp))

For Each c In rng
If InStr(1, c.Text, vWords(0), vbTextCompare) 0 Or _
InStr(1, c.Text, vWords(1), vbTextCompare) 0 Or _
InStr(1, c.Text, vWords(2), vbTextCompare) 0 Then

'color it gray
c.Offset(0, -7).Resize(1, 8).Interior.ColorIndex = 15

End If

Next c
End Sub


--
Hope that helps.

Vergel Adriano


"Greg Spencer" wrote:

Being new to VBA programming, I'm struggling to put together a macro that
will accomplish the following:

1. Search the cells in a specific column (H) - starting at row 3 - for the
presence of a particular word from a list of 3 different words.

2. If one of the words is found, the entire row (from columns A through H)
would be shaded.

3. The search would continue through the rest of the cells in the column
with the same action being repeated to the end of the column.

All help would be appreciated!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching for a string and then shading the row

That works great. Thanks!

Greg

"Vergel Adriano" wrote:

Greg,

Here's one way to do it:

Sub test()
Dim rng As Range
Dim c As Range
Dim vWords As Variant

vWords = Array("One", "Two", "Three")

Set rng = Range(Range("H3"), Range("H65535").End(xlUp))

For Each c In rng
If InStr(1, c.Text, vWords(0), vbTextCompare) 0 Or _
InStr(1, c.Text, vWords(1), vbTextCompare) 0 Or _
InStr(1, c.Text, vWords(2), vbTextCompare) 0 Then

'color it gray
c.Offset(0, -7).Resize(1, 8).Interior.ColorIndex = 15

End If

Next c
End Sub


--
Hope that helps.

Vergel Adriano


"Greg Spencer" wrote:

Being new to VBA programming, I'm struggling to put together a macro that
will accomplish the following:

1. Search the cells in a specific column (H) - starting at row 3 - for the
presence of a particular word from a list of 3 different words.

2. If one of the words is found, the entire row (from columns A through H)
would be shaded.

3. The search would continue through the rest of the cells in the column
with the same action being repeated to the end of the column.

All help would be appreciated!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching csv files for particular string NickHK Excel Programming 0 January 23rd 07 04:35 AM
Searching for string in other cells Ruatha Excel Worksheet Functions 3 June 9th 06 10:42 PM
searching through a string? funkymonkUK[_144_] Excel Programming 6 May 3rd 06 02:19 PM
Searching a String dcstech Excel Programming 2 April 6th 04 02:41 PM
searching a string with a partial string dcstech Excel Programming 1 April 5th 04 10:57 PM


All times are GMT +1. The time now is 01:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"