Multiply range

R

Rodrigo

Hi everyone!

Somebody please help me: I need to multiply all cells in a specific range object by a number (it could be any number--I would like to use the value property of a spin button, for instance) and return all the number to the corresponding cells of another range object with the same characteristics (same number of cells and with cells distributed in the same way relative to each other). I have already created "Old As Range" and "New As Range",...

Thank you very much in advance.

Regards,

Rodrigo
 
J

jacob

One way would be to copy the value you want to multiply
the range with, select the range and paste special with
operation multiply. Or you could do this



for i=1 to new.rows.count


-----Original Message-----

Hi everyone!

Somebody please help me: I need to multiply all cells
in a specific range object by a number (it could be any
number--I would like to use the value property of a spin
button, for instance) and return all the number to the
corresponding cells of another range object with the same
characteristics (same number of cells and with cells
distributed in the same way relative to each other). I
have already created "Old As Range" and "New As
Range",...
 
E

Edwin Tam (MS MVP)

Try the following macro. (Place it into a module.

Explanatio
=======
1) Declare two variables tmp1, tmp2, which are the "source range" and "target range" respectively
2) A variable "factor" is for setting the number to multiply with the source range

'--------------------------------------------------------------
Sub multiply_range(
Dim tmp1 As Range, tmp2 As Rang
Dim rr As Single, cc As Intege
Dim facto
Set tmp1 = Range("A2:C10"
Set tmp2 = Range("E2:G10"

factor =

For rr = 1 To tmp1.Rows.Coun
For cc = 1 To tmp1.Columns.Coun
If IsNumeric(tmp1.Cells(rr, cc).Value) The
tmp2.Cells(rr, cc) = tmp1.Cells(rr, cc).Value * facto
End I
Nex
Nex
End Su
'--------------------------------------------------------------

Regards
Edwin Ta
(e-mail address removed)


----- Rodrigo wrote: ----


Hi everyone

Somebody please help me: I need to multiply all cells in a specific range object by a number (it could be any number--I would like to use the value property of a spin button, for instance) and return all the number to the corresponding cells of another range object with the same characteristics (same number of cells and with cells distributed in the same way relative to each other). I have already created "Old As Range" and "New As Range",...

Thank you very much in advance

Regards

Rodrigo
 
M

Mikhail

Option Explicit
Sub Test()
Dim r1 As Range, r2 As Range
Dim cell As Range
Dim factor As Single
factor = 10
Set r1 = Range("A1:B4")
Set r2 = Range("F4:G7")
r2.Value = r1.Value
For Each cell In r2.Cells
cell.Value = cell.Value * factor
Next cell
End Sub

Rodrigo said:
Hi everyone!

Somebody please help me: I need to multiply all cells in a specific range
object by a number (it could be any number--I would like to use the value
property of a spin button, for instance) and return all the number to the
corresponding cells of another range object with the same characteristics
(same number of cells and with cells distributed in the same way relative to
each other). I have already created "Old As Range" and "New As Range",...
 

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