![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: May 2002
Posts: 19
|
Hello,
I am not sure if "ranking" is the proper term, but I am trying to write a macro that will number each row (A7=1,A8=2,A9=3,etc). For example, the data always starts at A7 but could end at A100 or A600-it varies. This would be applied to each worksheet for each workbook. (The number of worksheets in each workbook also varies.) Thanks in advance. -sam. |
|
|
|
|
|
#2 |
|
Join Date: Feb 2002
Location: Tampa, FL USA
Posts: 886
|
Hey,
I'm just getting used to VBA but how about something similar to: Code:
Sub numberrows()
Dim x As Integer
Dim MaxRow As Integer
x = 7
MaxRow = 600
For Each sht In Worksheets
Do While x < MaxRow
sht.Activate
Range("A" & x).Value = x - 6
x = x + 1
Loop
x = 7
Next sht
End Sub
Hope that helps, Adam [ This Message was edited by: Asala42 on 2002-05-22 11:43 ] |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,301
|
Quote:
=IF(ISBLANK(A7),"",ROW(A7)-6) This will put an empty string in the cell if A7 is blank. Hope this helps you out. Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
I thought Asala codes was great . However it sounded like you wanted this to occur in ALL workbooks that were open ... if thats the case then this modification of the code will take care of that situation.
Code:
Sub numberrows()
For Each WkBk In Workbooks
For Each sht In Worksheets
For x = 7 To 600
sht.Range("A" & x).Value = x - 6
Next
Next sht
Next WkBk
End Sub
|
|
|
|
|
|
#5 |
|
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Hi Sam99Car,
Heres what i use: This numbers all rows that are populated Starts in "A6" (adjust to suit) Private Sub CommandButton1_Click() Dim ColA As Range, Rw As Range, n% Set ColA = Range("A6") Set rw = ColA.EntireRow Do Until Application.Worksheet Function.CountA(rw)= 0 n = n + 1 ColA.Value = n Set ColA = ColA.Offset(1, 0) Set rw = rw.Offset(1, 0) Loop End Sub Regards, James |
|
|
|
|
|
#6 |
|
Join Date: May 2002
Posts: 19
|
Thank you ALL.
Asala and Nimrod's code is what I am looking for. -sam. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|