Index Columns

doonan36

New Member
Joined
Feb 28, 2017
Messages
10
If column B2 has Husband, B3 has Wife, B4-B5 has Child then starts over, how can I index each family unit ie: column A2 through A4 = 1 and increases with additional families.


[TABLE="width: 500"]
<tbody>[TR]
[TD]Index[/TD]
[TD]Member
[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Child[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Will "Husband" always denote the beginning of a new family? If so, enter 1 in A2 (next to the first Husband) and use the below formula:


Excel 2013/2016
AB
1IndexMember
21Husband
31Wife
41Child
51Child
62Husband
72Wife
82Child
93Husband
103Wife
114Husband
124Wife
134Child
Sheet3
Cell Formulas
RangeFormula
A3=IF(B3="Husband",A2+1,A2)
 
Upvote 0
If column B2 has Husband, B3 has Wife, B4-B5 has Child then starts over, how can I index each family unit ie: column A2 through A4 = 1 and increases with additional families.


[TABLE="width: 500"]
<tbody>[TR]
[TD]Index[/TD]
[TD]Member[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Child[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Husband[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Wife[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Child[/TD]
[/TR]
</tbody>[/TABLE]


This worked flawlessly, Thank you.

I modified it for blank cells.

=IF(ISBLANK(B3),"",IF(B3="Husband",A2+1,A2))

Cell A2=0


Do you have any suggestions on how to vb this?

Mark
 
Upvote 0
Give this code a shot:

Code:
Public Sub familyindex()
Dim i           As Long, _
    LR          As Long, _
    lngIndex    As Long

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

LR = Range("B" & Rows.Count).End(xlUp).Row

For i = 2 To LR
    Select Case Range("B" & i).Value
        Case "Husband"
            lngIndex = lngIndex + 1
            Range("A" & i).Value = lngIndex
        Case ""
            'Do Nothing
        Case Else
            Range("A" & i).Value = lngIndex
    End Select
Next i
        
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
        
End Sub

It generated the below results (I added some blank rows in there to demonstrate its capability to pass over them):


Excel 2013/2016
AB
1IndexMember
21Husband
31Wife
41Child
51Child
6
72Husband
82Wife
9
10
11
122Child
133Husband
143Wife
15
16
17
184Husband
194Wife
204Child
Sheet4
 
Upvote 0
I will give this a try and let you know how it works in my project... Thank you very much for your assistance on this.

Mark
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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