Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
CC CC is offline
external usenet poster
 
Posts: 91
Default select row if find word

Hi

I have this code to select the entire row when find a certain word in column
H
sometimes the word is in same column but in several Rows
is it possible select ALL rows where that word is ???


Sub RowsSHOW()
Dim k As Long, myWord As String
myWord = InputBox("Word to find?")
If myWord < "" Then
For k = Cells(Rows.Count, "H").End(xlUp).Row To 1 Step -1
If InStr(1, CStr(Cells(k, "H")), myWord, vbTextCompare) Then
Rows(k).EntireRow.Select
End If
Next k
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default select row if find word

You can build your range to select after each check.

Option Explicit
Sub RowsSHOW()
Dim k As Long
Dim myWord As String
Dim myRng As Range
Dim wks As Worksheet

Set wks = ActiveSheet

myWord = InputBox("Word to find?")

If myWord < "" Then
With wks
For k = .Cells(.Rows.Count, "H").End(xlUp).Row To 1 Step -1
If InStr(1, CStr(.Cells(k, "H")), myWord, vbTextCompare) Then
If myRng Is Nothing Then
Set myRng = .Cells(k, "A")
Else
Set myRng = Union(myRng, .Cells(k, "A"))
End If
End If
Next k
End With
End If

If myRng Is Nothing Then
MsgBox "Not found"
Else
'wks.Select 'not needed if you're processing the activesheet
myRng.EntireRow.Select
End If

End Sub

=================
Instead of looping through the cells, you may want to look at VBA's sample for
..FindNext.

Depending on the size of your data, you may find it works a lot faster.



CC wrote:

Hi

I have this code to select the entire row when find a certain word in column
H
sometimes the word is in same column but in several Rows
is it possible select ALL rows where that word is ???

Sub RowsSHOW()
Dim k As Long, myWord As String
myWord = InputBox("Word to find?")
If myWord < "" Then
For k = Cells(Rows.Count, "H").End(xlUp).Row To 1 Step -1
If InStr(1, CStr(Cells(k, "H")), myWord, vbTextCompare) Then
Rows(k).EntireRow.Select
End If
Next k
End If
End Sub


--

Dave Peterson
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
Word select from a string bridgjr Excel Worksheet Functions 3 August 4th 05 12:08 PM
auto word select jimmy Excel Discussion (Misc queries) 1 April 25th 05 01:17 PM
Auto Word Select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:19 AM
Auto Word Select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:19 AM
auto word select jimmy Excel Discussion (Misc queries) 0 April 25th 05 11:07 AM


All times are GMT +1. The time now is 09:45 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"