Computing.Net > Forums > Office Software > Excel Macro - Seqentially # Rows

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel Macro - Seqentially # Rows

Reply to Message Icon

Name: 24HG_Hoop
Date: August 27, 2007 at 15:09:51 Pacific
OS: XP
CPU/Ram: 3800 AMD, 2Gigs
Product: clone
Comment:

Hi all,

I'm trying to learn more about macros, so any help is appreciated.

I frequently compile a multi-column list of things, then sequentially number the rows after I've made any additions. I've got a header that takes up 9 rows, so the numbering starts in A10.

Column B in all of this is sorted by last name, so whenever new information comes in I frequently have to insert a new to maintain the alphabetical ordering of Column B.

After each insertion or deletion, I have to manually go to A10 and type in "1" and then go to A11 and type in =A10+1, and then drag that down to auto-copy the formula, creating the sequenced list.

This is probably uber-simple, but I can't auto record a macro to make this happen.



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: August 27, 2007 at 15:33:06 Pacific
Reply:

A better formula to use is =ROW()-9. If you place this in A10, it will return 1 since 10-9+1. Place it A11, it will return 2 since 11-9=2.

You can then insert rows where ever you want and then drag up or down just enough to fill in the blank numbers.

If you really want a macro...

This code will find the last cell in Column B that contains data and then fill A10:A-whatever with =ROW()-9

Note: The linewrap in this forum makes code look wierd. Paste it into a VBA window and you should get 2 lines of code between Sub...() and End Sub.

Sub AddRowNumbers()
LastRow = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A10:A" & LastRow).Formula = "=ROW()-9"
End Sub


0

Response Number 2
Name: Jennifer SUMN
Date: August 27, 2007 at 15:54:38 Pacific
Reply:

You could also use a page header rather than taking up the first nine rows of data. That way, your data would always start in cell A1.

Life's more painless for the brainless.


0

Response Number 3
Name: DerbyDad03
Date: August 27, 2007 at 18:23:16 Pacific
Reply:

While technically correct, a nine line page header is a pain to edit and all page headers are limited as far as how much formatting can be done.

In addition, I'm going to take a guess here and assume the header that the OP mentioned is not a true header, in that it is not repeated on every page.



0

Response Number 4
Name: 24HG_Hoop
Date: August 29, 2007 at 07:43:21 Pacific
Reply:

Thanks guys.

Yeah - not really a "header" that appears on every sheet, just a quick "summary" of the assumptions going into the columns [e.g., multiply what by what] and a summary of the end results [e.g., totals, maxs/mins, counts, etc.].

I wasn't aware of the ROW formula. Nice to know.

Thanks for the VB code too! I'm really most interested in the logic and the how-to behind macros to do a lot of things, so seeing it (much like finding out about ROW) is helpful to see.

Thanks again,
Hoop


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel Macro - Seqentially # Rows

Excel macro www.computing.net/answers/office/excel-macro/4051.html

Excel Macro; move row www.computing.net/answers/office/excel-macro-move-row/6623.html

Excel Macro help. www.computing.net/answers/office/excel-macro-help/8054.html