if statement in Macro

J

John

I am trying to write a macro where if cell A1 has a dollar amount put that
cell, however if cell A2 has a dollar amount put that cell. There only can
be one dollar amount, meaning you can have dollar amounts in cells A1 and A2.
This also has to be a macro. Any help would be great
 
F

Frank Kabel

Hi
do you mean

dim smsg
with activesheet
if .range("A1").value<>"" then
smsg=.range("A1").value
elseif .range("A2").value<>"" then
smsg=.range("A2").value
end if
end with
msgbox smsg
 
B

Bob Phillips

Iif (Range("A1").Value <> "" ,Range("A1").Value,Range("A2").Value )

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
J

John

HI

I think that is it, but i forgot to mention that if one of the cells has a
dollar amount in it, it needs to put that dollar amount into a different
cell, say A3, instead of the message box
 
F

Frank Kabel

dim smsg
with activesheet
if .range("A1").value<>"" then
smsg=.range("A1").value
elseif .range("A2").value<>"" then
smsg=.range("A2").value
end if
.range("A3").value=smsg
end with
 
J

John

Hi, Again

You have been an incredible help. Can i through one more loop into this
whole thing. Lets say that cell A1 is in sheet 1, Cell A2 is in sheet 2, and
cell A3 is in sheet 3. Can this be done? I promise that will be the last
question.
 
F

Frank Kabel

Hi

if worksheets("sheet1").range("A1").value<>"" then
smsg=worksheets("sheet1").range("A1").value
elseif worksheets("sheet2").range("A2").value<>"" then
smsg=worksheets("sheet2").range("A2").value
end if
worksheets("sheet3").range("A3").value=smsg
end with
 

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