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 is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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
 
Upvote 0

Forum statistics

Threads
1,222,175
Messages
6,164,397
Members
451,889
Latest member
invalidlabel

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