![]() |
![]() |
|
|||||||
| 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 |
|
New Member
Join Date: Apr 2002
Posts: 14
|
I am constantly adding rows to an Excel database, and I want to automatically number the records from 1 to x, x being last row. The code that follows works - but seems awkward because, since my data starts at row 6, I have to subtract 5 from the Row (function?). I thought that I could use .Count, but it didn't work. What is the command/function to count the total rows (not the row number) and then use it as a variable to auto fill to?
Sub colfill() ' ' colfill Macro ' Macro recorded 4/16/2002 by Preferred Customer ' Range("a6") = 1 RowCount = Range("b6").End(xlDown).Row - 5 ' Application.Goto Reference:="R6C1" Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _ Step:=1, Stop:=RowCount, Trend:=False End Sub Thanks, SJK |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi sjk. Pls try this.
Sub colfill() Range("A6").Value = 1 Range("A6", Range("B65536").End(xlUp).Offset(, -1)).DataSeries 2, Step:=1 End Sub Regards, Colo |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Posts: 14
|
Hi Colo: Yes, your program worked perfectly. I am trying to learn VBA and I am somewhat overwhelmed. Can I ask: did you know the solution just from experience, or did you look it up? I know that some basic ones can be built by using the Macro recorder. Thanks, SJK.
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi sjk.
I began to use "excel" since two years ago.Those days, I could only use the Macro recorder. There was no person using Excel around me. So, how to solve my problem was read the help and watched some web site. The persons who have own problem gather on bbs site. On the site, I could find the topic which could solve my problem. Regards, Colo |
|
|
|
|
|
#5 |
|
New Member
Join Date: Apr 2002
Posts: 14
|
Hi Colo: Thanks for the advice. I am gradually learning. I agree: this site is very helpful. I have also found it helpful to take some programming language and go through it line by line, and even to re-enter the code. Sructures become familiar.. SJK
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|