Select Rows based on cell value

kamalm

New Member
Joined
Jul 30, 2018
Messages
33
Hi, I use this code to select all Rows that contain number 3 based on column F. The code will select the Entire Row. But what I really want is the Rows contain number 3 to be selected only until Column X, not the entire Row. How can I do that ?

Code:
Sub SelRows()
Dim ocell As Range
Dim rng As Range


For Each ocell In Range("F:F")


If ocell.Value = "3" 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
 
Last edited:
You said:
Actually after I select all the Rows that contain number 3, I want to cut and paste at AA1.

Not sure how the script in Post 7 does what you want. But if your happy that's all that counts.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Code:
Sub SelRows()
Dim rng As Range, r&
Rows(1).Insert
[F:F].AutoFilter Field:=1, Criteria1:="3"
r = Cells(Rows.Count, "F").End(xlUp).Row
If r > 1 Then
    Set rng = Intersect(Range("F2:F" & Cells(Rows.Count, "F").End(xlUp).Row) _
        .SpecialCells(xlCellTypeVisible).EntireRow, [A:X])
[COLOR=#ff0000]    rng.Copy [AA2][/COLOR]
[COLOR=#ff0000]    rng.Delete Shift:=xlUp[/COLOR]
End If
Rows(1).Delete
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top