View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default How do I create a macro to add zeros in front of a value?

As written the macro operates on any column from the activecell to the bottom of
the column.

You do know that by adding the zeros you are changing the numbers to text?

For a specific range use this version.

Sub test22()
Set thisrng = Range("B1:B20")
For Each cell In thisrng
cell.Value = "00" & cell.Value
Next
End Sub

To select a range use this version.

Sub test33()
Set thisrng = Application.InputBox(prompt:= _
"Select the range of cells.", Type:=8)
For Each cell In thisrng
cell.Value = "00" & cell.Value
Next
End Sub

How will Excel know which cells are to receive 3 zeros or 2 zeros?


Gord




On Mon, 18 Sep 2006 14:38:02 -0700, rexie3
wrote:

Thank you so much! Question: Would I be able to run this macro for a number
of rows within my column? For example, I would want to run it for 20 rows in
Column B. How do I do that?

I have to add 3 zeros in some cells and others 2 zeros, etc. How do I tell
the macro to repeat itself for a number of rows down a column?

"Gord Dibben" wrote:

Sub test()
Set thisrng = Range(ActiveCell, Cells(Rows.Count, _
ActiveCell.Column).End(xlUp))
For Each cell In thisrng
cell.Value = "00" & cell.Value
Next
End Sub


Gord Dibben MS Excel MVP

On Mon, 18 Sep 2006 09:15:02 -0700, rexie3
wrote:

PLEASE SOMEONE HELP ME!!!

I have to add zeros to over 61,000 line items in excel. I need to know how
to create a macro that will enable me to select a range within the same
column and have zeros added to the the numbers in the cell.

I would be eternally greatful.
Thanking you in advance.




Gord Dibben MS Excel MVP