Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Find All.... Then Select All

Given the range A1:A1000, I'm trying to write some code that will look in the
values throughout the range, find all those cells that have the word "Test"
(or other critieria) in them, and then select all of these cells.

I have tried to use the Find function in excel to do this, and while I can
use this function to find all values in a given range, I'm not able to then
immediately select these same values. Thanks for your help.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Find All.... Then Select All

I copied the stuff from VBA's help and made some minor changes:

Option Explicit
Sub testme()

Dim myRng As Range
Dim FoundCell As Range
Dim AllCells As Range
Dim FirstAddress As String
Dim whatToFind As String

whatToFind = "test"

Set myRng = ActiveSheet.Range("a1:A1000")

With myRng
Set FoundCell = .Cells.Find(what:=whatToFind, _
after:=.Cells(.Cells.Count), LookIn:=xlValues, _
lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False)

If FoundCell Is Nothing Then
'do nothing
Else
FirstAddress = FoundCell.Address
Do
If AllCells Is Nothing Then
Set AllCells = FoundCell
Else
Set AllCells = Union(FoundCell, AllCells)
End If
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address < FirstAddress
End If
End With

If AllCells Is Nothing Then
MsgBox whatToFind & " wasn't found"
Else
AllCells.Select
End If

End Sub

Take a look at that .find line. You'll want to adjust it to match what you need
(xlwhole/xlpart, matchcase stuff).



Jason wrote:

Given the range A1:A1000, I'm trying to write some code that will look in the
values throughout the range, find all those cells that have the word "Test"
(or other critieria) in them, and then select all of these cells.

I have tried to use the Find function in excel to do this, and while I can
use this function to find all values in a given range, I'm not able to then
immediately select these same values. Thanks for your help.


--

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
Find & Select Celeste[_2_] Excel Discussion (Misc queries) 3 December 1st 09 05:52 PM
SELECT ALL ROWS IF FIND CC Excel Discussion (Misc queries) 2 October 15th 09 06:43 PM
find & select Aaron Hodson \(Coversure\) Excel Worksheet Functions 2 August 21st 08 08:36 AM
Find then select to the right JUAN Excel Programming 2 April 30th 04 09:49 PM
How to find a value then select that column Sevcav Excel Programming 1 November 5th 03 02:18 AM


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