Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default numbering items in a column based on a condition

I need a procedural method to number a column for an entire worksheet
based upon a condition.

So, if text exists in column B?, then add a sum to A? cell next to it.

Column A Column B
1 Text
2 Text
No Text
3 Text
4 Text

It has to be smart enough to number all columns in all worksheets.

So, if the last number in Worksheet A was 50, then the next number in
Worksheet B would start at 51.


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default numbering items in a column based on a condition

Following doesn't choke on blank sheets:

Option Explicit

Sub Main()
Dim wks As Worksheet
Dim cell As Range
Dim rng As Range
Dim count As Long
Dim oldStatusBar As Boolean
count = 0
Application.ScreenUpdating = False
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True

For Each wks In Worksheets
Set rng = Intersect(wks.Columns("B"), wks.UsedRange)
If Not rng Is Nothing Then
For Each cell In rng.Cells
If Len(cell.Text) 0 Then
count = count + 1
cell.Offset(0, -1).Value = count
Application.StatusBar = count
End If
Next cell
End If
Next wks

Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
Application.ScreenUpdating = True
End Sub

"pacman2k4 " wrote in message
...
I need a procedural method to number a column for an entire worksheet
based upon a condition.

So, if text exists in column B?, then add a sum to A? cell next to it.

Column A Column B
1 Text
2 Text
No Text
3 Text
4 Text

It has to be smart enough to number all columns in all worksheets.

So, if the last number in Worksheet A was 50, then the next number in
Worksheet B would start at 51.


---
Message posted from http://www.ExcelForum.com/




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default numbering items in a column based on a condition

Worked like a charm. Where should I send a check to

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default numbering items in a column based on a condition

I find your problem statement a little confusing, but here is a brute force
approach to numbering rows in A where text occurs in B.

Option Explicit

Sub Main()
Dim wks As Worksheet
Dim cell As Range
Dim count As Long
Dim oldStatusBar As Boolean
count = 0
Application.ScreenUpdating = False
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True

For Each wks In Worksheets
For Each cell In Intersect(wks.Columns("B").Cells, wks.UsedRange)
If Len(cell.Text) 0 Then
count = count + 1
cell.Offset(0, -1).Value = count
Application.StatusBar = count
End If
Next cell
Next wks

Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
Application.ScreenUpdating = True
End Sub


"pacman2k4 " wrote in message
...
I need a procedural method to number a column for an entire worksheet
based upon a condition.

So, if text exists in column B?, then add a sum to A? cell next to it.

Column A Column B
1 Text
2 Text
No Text
3 Text
4 Text

It has to be smart enough to number all columns in all worksheets.

So, if the last number in Worksheet A was 50, then the next number in
Worksheet B would start at 51.


---
Message posted from http://www.ExcelForum.com/




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
Functions expert€¦€¦€¦numbering random condition in a column JVANWORTH Excel Worksheet Functions 15 April 2nd 09 01:25 AM
Counting items in one column based on criteria in another column luttona Excel Worksheet Functions 3 June 13th 08 06:00 PM
Counting entries in column based on condition in another column RobertR Excel Worksheet Functions 1 February 8th 07 03:54 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
help me getting value of column based on condition amrezzat Excel Worksheet Functions 2 November 12th 05 06:18 PM


All times are GMT +1. The time now is 06:48 PM.

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"