LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Update this macro to make it generate a counter as text

I have the macro listed below that does generate a numeric value for each cell in column D for as many rows as there are records. I would like to adjust this macro to where if the counter is less than 10, that the active cell would get 001,002 etc. If it is 35, it should past 035 as text, and if its 625, it would not have to paste any leading zeroes in that case. So, I guess I need a case or a series of if then else type structure, but I am not sure how to format the "0", "00", or no leading zeroes depending on the number involved.


Sub add_page_and_line_new()
Dim cRows As Long
cRows = Cells(Rows.Count, "A").End(xlUp).Row
Dim linenumcounter As Integer
linenumcounter = 1
Range("d1").Select
For i = 1 To cRows

If linecounter < 10 Then

With ActiveCell
.Value = linenumcounter
.Copy
.PasteSpecial Paste:=xlValues
.Offset(1, 0).Select
End With
linenumcounter = linenumcounter + 1

End With
Next
 
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
How to generate a text file from Excel using a macro or script Frank Excel Programming 5 January 18th 08 07:03 PM
How to generate a text file from Excel using a macro or script Ron de Bruin Excel Programming 0 January 7th 08 11:12 PM
How to generate a text file from Excel using a macro or script? Frank Excel Discussion (Misc queries) 1 January 6th 08 05:11 PM
How to generate a text file from Excel using a macro or script? Frank Excel Discussion (Misc queries) 0 January 6th 08 05:11 PM
Generate Numbers (not random) Like a counter Lloyd Excel Discussion (Misc queries) 2 September 6th 06 01:50 PM


All times are GMT +1. The time now is 08:41 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"