Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find All.... Then Select All
try either datafilterautofilter
or look in the visual basic editor HELP for find. There is a good example of findnext -- Don Guillett SalesAid Software "Jason" wrote in message ... 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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find & Select | Excel Discussion (Misc queries) | |||
SELECT ALL ROWS IF FIND | Excel Discussion (Misc queries) | |||
find & select | Excel Worksheet Functions | |||
Find then select to the right | Excel Programming | |||
How to find a value then select that column | Excel Programming |