ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiply range (https://www.excelbanter.com/excel-programming/282527-multiply-range.html)

Rodrigo[_2_]

Multiply range
 

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

Jacob

Multiply range
 
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",...

Thank you very much in advance.

Regards,

Rodrigo
.


Edwin Tam (MS MVP)

Multiply range
 
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



----- 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

Mikhail

Multiply range
 
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" сообщил/сообщила в новостях
следующее: ...

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





All times are GMT +1. The time now is 10:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com