Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to generate a text file from Excel using a macro or script | Excel Programming | |||
How to generate a text file from Excel using a macro or script | Excel Programming | |||
How to generate a text file from Excel using a macro or script? | Excel Discussion (Misc queries) | |||
How to generate a text file from Excel using a macro or script? | Excel Discussion (Misc queries) | |||
Generate Numbers (not random) Like a counter | Excel Discussion (Misc queries) |