Help with defining ranges

rc090320

New Member
Joined
Mar 7, 2006
Messages
36
Hi

I have a small data set where in column "A" I have key indicators defining what each row means.

What I wanted to know is how can I write a VBA code where it intuitively selects the row range of consecutive "G" values in column "A".

Thanks in advance

Ronnie
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
Hi Ronnie. Here is one way. Please add your own error checking, etc. Regards, Fazza
Code:
Sub test()

    Dim rngFirstG As Range
    Dim rngLastG As Range
    
    With Columns(1)
        Set rngFirstG = .Find(What:="G", After:=.Cells(.Cells.Count), LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext)

        Set rngLastG = .Find(What:="G", After:=.Cells(1), LookIn:=xlValues, _
            LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
    End With
        
    Range(rngFirstG, rngLastG).EntireRow.Select

End Sub
 

Forum statistics

Threads
1,181,102
Messages
5,928,073
Members
436,587
Latest member
Slicesofquince

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
Top