ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   if statement in Macro (https://www.excelbanter.com/excel-worksheet-functions/8420-if-statement-macro.html)

John

if statement in Macro
 
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

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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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




Bob Phillips


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

--

HTH

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


"John" wrote in message
...
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




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

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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





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

--
Regards
Frank Kabel
Frankfurt, Germany

John wrote:
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

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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




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.

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany

John wrote:
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

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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





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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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.

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany

John wrote:
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

"Frank Kabel" wrote:

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

--
Regards
Frank Kabel
Frankfurt, Germany
"John" schrieb im Newsbeitrag
...
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








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

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