If/else statement on a specific value in Excel

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
MadsSEB
Newbie
Posts: 4
Joined: Fri Nov 02, 2018 9:59 am

If/else statement on a specific value in Excel

Post by MadsSEB » Fri Nov 02, 2018 10:04 am

Hey

So I have a list of companies in a Excel document and I want to "seperate" them in to two categories. "DD" and "EDD".

So everytime my macro meets a column with the value "DD" it should //do something
and same with "EDD" it should do //something else.

How do I do this? What's the syntax for that? I'm pretty new in Macro Scheduler.

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: If/else statement on a specific value in Excel

Post by Marcus Tettmar » Fri Nov 02, 2018 4:04 pm

As you loop through just compare with the If statement. Assume you are looping through and using XLGetCell to get the data. Let's assume you use the variable name strValue to return the item:

Code: Select all

If>strValue=DD
  //do something
Endif

If>strValue=EDD
  //do something else
Endif
Have a look at:
https://help.mjtnet.com/article/9-makin ... -and-endif

And:
https://help.mjtnet.com/article/138-tra ... or-web-app

And:
https://help.mjtnet.com/article/144-how ... p-the-loop
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadsSEB
Newbie
Posts: 4
Joined: Fri Nov 02, 2018 9:59 am

Re: If/else statement on a specific value in Excel

Post by MadsSEB » Mon Nov 05, 2018 7:24 am

Hey Marcus - thanks for your reply. I'll try again :) And thanks for the links

MadsSEB
Newbie
Posts: 4
Joined: Fri Nov 02, 2018 9:59 am

Re: If/else statement on a specific value in Excel

Post by MadsSEB » Mon Nov 05, 2018 7:53 am

Hello Marcus - I hope this image explains what im trying to do.

This is my code so far:


setFocus>Microsoft Excel*
wait>0.5

IF>(%DECIDED DD LEVEL IN CAC% = "DD") AND (%CONDITIONS/COMMENTS% = "Reason code should be "CAC decision, not HRI")

setFocus>SEB Kort*
//do something more

ELSE

press down
//go for the next row

ENDIF

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: If/else statement on a specific value in Excel

Post by Marcus Tettmar » Mon Nov 05, 2018 4:21 pm

I assume you have removed some of your code for brevity so I'm not sure where the variables %DECIDED DD LEVEL IN CAC% and %CONDITIONS/COMMENTS% are coming from but I would advise against using spaces in variable names.

Presumably you are using XlGetCell in a loop as per the sample macro in your sample folder. If so you don't need the SetFocus. Since you have it, perhaps you are copying to the clipboard and using GetClipboard? I'd use XLGetCell.

See:
https://help.mjtnet.com/article/138-tra ... or-web-app

And see the example script included with the software which reads from Excel and outputs to Notepad.
IF>(%DECIDED DD LEVEL IN CAC% = "DD") AND (%CONDITIONS/COMMENTS% = "Reason code should be "CAC decision, not HRI")
You need to change this line to:

IF>{(%DECIDED DD LEVEL IN CAC% = "DD") AND (%CONDITIONS/COMMENTS% = "Reason code should be "CAC decision, not HRI")}

But as stated I'd also rename your variables. With spaces and / characters etc in variables you are bound to run into issues.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadsSEB
Newbie
Posts: 4
Joined: Fri Nov 02, 2018 9:59 am

Re: If/else statement on a specific value in Excel

Post by MadsSEB » Fri Nov 09, 2018 8:17 am

Okay, I'll try take a closer look at that link again. The variables, by the way, I got from the If/else advanced expression inside of Macro itself, but I wasn't even sure if that was did right tbh..

But you would suggest me to use XLGetCell in this case?

Again, thanks for your time and help. Much appreciated.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts