Ranges with Variable start and end based on number of lines of data

SAMCRO2014

Board Regular
Joined
Sep 3, 2015
Messages
160
I feel like I have myself running around in circles. I need a macro that will create a variable range based on the number of rows that contain specific information. The start and end of each range is variable. The columns are not variable.

For example: Employee 123 has 6 rows of data so the range would be B7:B12
Employee 456 has 10 rows of data so the range could be B37:B46
Employee 789 has 2 rows of data so the range could be B99:B100

Any help would be greatly appreciated.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try:

Code:
Sub ranges()
    Dim datos As Range, i As Long, n As Long, rng As String
    Set datos = Range("B7", Range("B" & Rows.Count).End(xlUp))
    For i = 1 To datos.Rows.Count
        n = WorksheetFunction.CountIf(datos.Columns(1), datos(i, 1))
        rng = datos(i, 1).Resize(n, 1).Address
        MsgBox "Employee : " & datos(i, 1) & " Range : " & rng
        i = i + n - 1
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,719
Members
452,995
Latest member
isldboy

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