PDA

View Full Version : [SOLVED] Select multiple rows based on cell value



sujittalukde
07-09-2009, 12:58 AM
I am using the following code to select the entire row where cell value is equal to "Total"
But this code is not selecting the entire row of all the cells containing the value "Total" and only selects the Last cell row.

This is what I have observed that the code releases the lase selection when new row is selected.

How can I fix the problem?

code is:


Sub SelRows()
Dim ocell As Range
For Each ocell In Range("B1:B10")
If ocell.Value = "Total" Then
ocell.EntireRow.Select
End If
Next
End Sub

Bob Phillips
07-09-2009, 02:01 AM
Sub SelRows()
Dim ocell As Range
Dim rng As Range
For Each ocell In Range("B1:B10")
If ocell.Value = "Total" Then
If rng Is Nothing Then
Set rng = oCcell.EntireRow
Else
Set rng = Union(rng, ocell.EntireRow)
End If
End If
Next
If Not rng Is Nothing Then rng.Select
Set rng = Nothing
Set ocell = Nothing
End Sub

Bob Phillips
07-09-2009, 02:01 AM
Sub SelRows()
Dim ocell As Range
Dim rng As Range
For Each ocell In Range("B1:B10")
If ocell.Value = "Total" Then
If rng Is Nothing Then
Set rng = ocell.EntireRow
Else
Set rng = Union(rng, ocell.EntireRow)
End If
End If
Next
If Not rng Is Nothing Then rng.Select
Set rng = Nothing
Set ocell = Nothing
End Sub

sujittalukde
07-09-2009, 02:16 AM
Thanks xld, its working
One typo is there:
Set rng = oCcell.EntireRow

should be:
Set rng = ocell.EntireRow

Bob Phillips
07-09-2009, 02:27 AM
Sorry, just rattled it off.

Dancul
02-08-2019, 08:59 AM
Hi

Thank you, this code help to me also

But I can not solve If I just want to select not EntireRow but only for example to I column

Regards

Paul_Hossler
02-08-2019, 10:25 AM
Welcome

Please take a minute to review the links in my signatire to the FAQs

However , this was a 10 year old post. It's better if you started a new one with a complete and stand alone description of your question

Use the[+Post New Thread] button top left to start a new one

Dancul
02-08-2019, 12:14 PM
Hello Paul

And Thank you for your reply

Regards
Dan