ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple row selection (https://www.excelbanter.com/excel-programming/308579-multiple-row-selection.html)

Minh

Multiple row selection
 
Hello,

Is there a way to select multiple rows given a certain
criteria is met? I have the following code which only
selects one row at a time, but I would like the code to
select all the rows for which the cell in the Range is
equal to "Cat".

Dim R As Range, Cel As Range
Set R = Range("A8:A27")
Set Cel = Range("A8:A27")
For Each Cel In R
If Cel.Value = "Cat" Then _
Cel.EntireRow.Select
Next Cel

Thank you in advance.

Dave Peterson[_3_]

Multiple row selection
 
Dim R As Range, Cel As Range
dim AllCat as Range
Set R = Range("A8:A27")
Set Cel = Range("A8:A27")
set allcat = nothing

For Each Cel In R
If Cel.Value = "Cat" Then
if allcat is nothing then
set allcat = cel
else
set allcat = union(cel, allcat)
end if
end if
next cel

if allcat is nothing then
'nothing to select
else
allcat.entirerow.select
end if


Minh wrote:

Hello,

Is there a way to select multiple rows given a certain
criteria is met? I have the following code which only
selects one row at a time, but I would like the code to
select all the rows for which the cell in the Range is
equal to "Cat".

Dim R As Range, Cel As Range
Set R = Range("A8:A27")
Set Cel = Range("A8:A27")
For Each Cel In R
If Cel.Value = "Cat" Then _
Cel.EntireRow.Select
Next Cel

Thank you in advance.


--

Dave Peterson



All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com