Adding zero's to a group of cells

G

Guest

Hello, I need to figure out a way to convert a group of cells from three
digits to six. Essentially I want to take the numbers in the cells and
multiply them by 1000. I do not however want to go into each cell and add
the formula. I am creating a macro and this is the last piece of this.
Essentially I am looking for an easy out.
 
G

Guest

hi
try this....
Sub mactest()
Dim r As Range
Dim s As Range
Set r = Range("A1:E10")

For Each s In r
s.Value = s.Value * 1000
Next s
End Sub

worked in xl2k

regards
FSt1
 
R

Roger Govier

One way
In a blank cell on your sheet enter 1000
Copy that cell
Mark the range of your data
Paste Special>Multipy
 
D

David McRitchie

Hi Desiree,
Sorry had not read the question completely before starting an answer
to notice that you were writing a macro anyway/ The correct
group for macro questions is the programming group, but
mentioning the macro at least told us you know how to
install a macro.

you might compare this to the solution you were already provided, it
will reduce the cells processed to those in the selection range
that are numeric constants.

Sub macro11()
Dim cell As Range, rng As Range
Set rng = Intersect(Selection, _
Cells.SpecialCells(xlCellTypeConstants, xlNumbers))
If Not rng Is Nothing Then
For Each cell In rng
cell = cell * 1000
Next cell
End If
End Sub

The use of SpecialCells automatically limit the range to
the usedrange and the the operands are limiting it furtyer
to constants which are numeric. So you could apply it
to entire columns without trying to process each cell.

More on use of SpecialCell in
http://www.mvps.org/dmcritchie/excel/proper.htm with
additional portions in formula.htm


The rest was that I hadn't noticed you were looking for
a macro solution. Anything that shows a specific range
is kind of a warning that the solution is not a generic
one and that is why it first caught my attention.

For a non macro solution:
For multiplying cells a user specified range by 1000.

Anyway non macro solution.
Place 1000 into a cell, and copy it Ctrl+C
Then make a selection of the cells you want to change, then.
Edit menu, Paste Special, multiply
This solution will work on both constants and formula, may look
a little messy if you multiply formulas but you get what you ask for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top