After Using AutoFilter, Need to Renumber Rows

shqiptar

New Member
Joined
Aug 4, 2006
Messages
34
Hi all. I would appreciate the help on this... When using autofilter, I need to be able to renumber the rows... Column A counts the number of accounts in the whole roster. When I filter for a team member, I need it to restart the numbering from 1 on down, not to display the original numbers. Thanks in advance.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I do not know of a way to do this with formulas. Perhaps a guru could weigh in on that one. However here is a UDF you could use in the mean time:
Code:
Option Explicit
Function AUTONUMBER(ByVal oRng As Excel.Range, Optional bCountFromZero As Boolean = True) As Long
    Excel.Application.Volatile True
    On Error GoTo Err_Hnd_AN
    Dim oRngCol As Excel.Range
    Dim oWS As Excel.Worksheet
    If oRng.Cells.Count <> 1 Then VBA.Err.Raise vbObjectError + 777
    Set oWS = oRng.Parent
    'Used range gets rid of blanks in the upper portion of column, oWS.Rows("1:" & oRng.Row) limits
    'the range to the cell in question up.
    Set oRngCol = Excel.Intersect(oWS.Columns(oRng.Column), oWS.UsedRange, oWS.Rows("1:" & oRng.Row))
    AUTONUMBER = oRng.Row - GetInvisibleRows(oRngCol)
    If bCountFromZero Then AUTONUMBER = AUTONUMBER - 1
    Exit Function
Err_Hnd_AN:
End Function
Private Function GetInvisibleRows(oRng As Excel.Range) As Long
    'SpecialCells(xlCellTypeVisible).Count does not work when
    'called from macro.
    Dim oWS As Excel.Worksheet
    Dim lLC As Long     'Loop Counter
    Dim lUB As Long     'Loop Upper bound
    Dim lSum As Long
    Set oWS = oRng.Parent
    lUB = oRng.Rows.Count
    For lLC = 1 To lUB
        If oWS.Rows(lLC).RowHeight = 0 Then lSum = lSum + 1
    Next lLC
    GetInvisibleRows = lSum
End Function
To use:
  1. Press Alt F11 to Launch VBE.
    On Insert Menu select "Insert Module".
    In Module paste code.
    Put this formula in Cell A2:
    Code:
    =AUTONUMBER(A2)
    Copy Forumla down as needed.
 
Upvote 0
Thanks Oorang, but can this be used repeatedly, that is,as I filter for the next salesperson, it would re-do the process automatically?
 
Upvote 0
Actually, that works great. Thanks again. Just a quick question... What do I need to do to start the counting in cell A3, instead of A2? Thanks
 
Upvote 0
Hi

A formula solution. If the team members you are filtering are in column B write in A3:

=SUBTOTAL(3,$B$3:B3)
Copy down

Hope this helps
PGC
 
Upvote 0

Forum statistics

Threads
1,221,481
Messages
6,160,080
Members
451,616
Latest member
swgrinder

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