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.
If/else statement on a specific value in Excel
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: If/else statement on a specific value in Excel
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:
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
Code: Select all
If>strValue=DD
//do something
Endif
If>strValue=EDD
//do something else
Endif
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: If/else statement on a specific value in Excel
Hey Marcus - thanks for your reply. I'll try again
And thanks for the links

Re: If/else statement on a specific value in Excel
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: If/else statement on a specific value in Excel
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")}
But as stated I'd also rename your variables. With spaces and / characters etc in variables you are bound to run into issues.
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.
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")
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: If/else statement on a specific value in Excel
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.
But you would suggest me to use XLGetCell in this case?
Again, thanks for your time and help. Much appreciated.