Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default record counter based on column value

Here's how I approach this...

I use local scope (sheet level) defined names for ranges rather
extensively (as a 'best practice') so my formulas (or code) is better
'self-documented' and so easier to understand. Local scope also allows
me to reuse the same name[s] on other sheets in the same workbook
without conflict.

Define local scope names as follows...

'Sheet Name'!DefinedName

...where the apostrophes wrap the sheet name when it contains spaces.
Otherwise, the apostrophes aren't required. Note that the exclamation
(!) character is used to delimit the string.

Make sure *A2* is selected and create the following names in the Define
Name dialog. (Assumes sheetname is "Orders"

Name1: orders!LastCell
RefersTo: =A1

Name2: orders!ThisOrderNum
RefersTo: =$B2

Name3: orders!AboveOrderNum
RefersTo: =$B1

Name4: orders!OrderCount
RefersTo: =IF(ThisOrderNum<AboveOrderNum,LastCell+1,LastCel l)

Note that while this name method works in all versions of Excel, the
later versions allow you to select the sheetname from the 'Scope:'
dropdown. (I typically copy everything from the exclamation and left to
save extra steps when entering multiple names)

How this works:
Requires A1 is *blank* because A2 needs to start at 1.
If your column *requires* a header then insert a blank row below
the headers and hide it

-OR-
manually enter 1 to start the counter in A2.

All 3 cell names are row-relative refs to the cell containing the
formula using those names;

Names 2&3 are column-absolute so your counter can be used in any
column you wish;

Enter the following formula in A2 and copy down...
=OrderCount
..or select all cells to receive the formula, enter it once, then
use Ctrl+Enter to populate the selection.

This method will auto-adjust if rows are inserted/deleted.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple record counter scubadiver Excel Programming 1 January 19th 09 12:07 PM
Copy Record to Appropriate Worksheet Based on Contents of Column A - VBA. Si[_2_] Excel Programming 7 February 2nd 07 07:33 AM
Should I use Do-While loop for my record counter? excelnut1954 Excel Programming 0 March 24th 06 09:25 PM
Can somebody explain to me how Bob Phillips' unique record counter works? Ken Johnson Excel Programming 4 September 22nd 05 10:59 PM
Program Column B to record numerical range based on number in colm Nikole Excel Discussion (Misc queries) 2 August 17th 05 08:37 PM


All times are GMT +1. The time now is 05:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"