It possible to multiply one cell by...?

J

jose luis

Hi,

I'm trying to multiply a range of values (A1:A20) by a fixed numbe
contained in a cell (c1) only if it equals certain condition.
(A1,A2,....etc. = D1). (from VBA).

Any idea?

Thanks a lot

jose lui
 
F

Frank Kabel

Hi
try
sub foo()
dim rng as range
dim cell as rng
with activesheet
set rng = .range("A1:A20")
for each cell in rng
if cell.value=.range("D1").value
cell.value=cell.value*2
end if
next
end with
end sub
 
J

jose luis

Thank you Frank

I think your proposal is the solution to my problem. Now i 'm havin
troubles with the syntaxis. When I run the Macro i get a "user-define
type not defined". I think the assigment of rng as Range and then cel
as rng is not working. Could you continue helping me to get this done?

As you see I 'm not very knowlegdable in VBA .But "with a little hel
from my friends" all can be done.


Thanks again!!!

Jose Luis
Monterrey
Mexico

What an amazing thing is the Internet!!!, I can stop be surprised! b
the COMMUNity achieved
 
M

Myrna Larson

I haven't seen the code, but if you have

Dim Rng As Range
Dim Cell As Range

Rng is a variable, not a prototype for another variable. The prototype for
both is Range.
 
A

Andoni

Sub TryThis()

'Llamemos Valor al rango que
'contiene el valor que has
'llamado fixed number

Dim Valor As Range
Set Valor = Range("C1")

'Los Valores que seran multiplicados por
'el valor que se encuentra en la celda
'Range("C1"), "Valor"
'los identificaremos con Rg

Dim Rg As Range
Set Rg = Range("A1:A20")

'Y aqui la operacion
'propiamente dicha:

Valor.Copy
Rg.PasteSpecial _
Paste:=xlPasteAll, _
Operation:=xlMultiply, _
SkipBlanks:=False, _
Transpose:=False

End Su
 
J

jose luis

Thank you all!!!


Frank
Myrna
Andoni


Your advice was followed and the task completed!!!

The Andoni's solution was helpfull to learn a new approach to th
problem. Myrna's advice was the key to make run the Macro proposed b
Frank. I just change the rng definition and the macro ran.

Thank you all again, hope to see you around!!


Regards

Jose Lui
 
Top