Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Basic Macro to Set Variable and Select in Field

I am brand new to Macros and just need a simple macro that I will run OnActivateSheet that will:

  1. Set a Variable:  vTest

          = if (vBlob = 'test', 'Value1', 'Value2')

  2. Select in Field:  myFilter 

          = '>=$(EndDate)'

All the example macros are very complex and I am not sure what the minimum is I need to include to just perform the above actions. I had these actions set up individually (without macro), but need to assure that the variable is set before the field is selected.

Thanks

4 Replies
Not applicable
Author

You don't need a macro for this and, in fact, I highly recommend avoiding them whenever possible.  Go to Settings > Sheet Properties > Triggers < OnActivateSheet > Add Action(s) > Add > External > Set Variable for the first one. Then do the same thing, but select Selection > Select in Field for the second one.

Not applicable
Author

Some background on my I am looking into using a macro:  Sheet OnActivateSheet action not working properly | Qlik Community

Not applicable
Author

Thanks Rebecca, I agree, I was hoping to do this without a macro, but here is some background:

Sheet OnActivateSheet action not working properly | Qlik Community

jerem1234
Specialist II
Specialist II

I agree with Rebecca Camper. You can accomplish this using triggers. Macros should be a last resort. But if you are curious as to the code, here is some code that does what you ask as a macro:

sub Test

set vBlob = ActiveDocument.Variables("vBlob")

set vTest = ActiveDocument.Variables("vTest")

set EndDate = ActiveDocument.Variables("EndDate")

if vBlob.GetContent.String = "test" then

vTest.SetContent "Value1",true

else

vTest.SetContent "Value2",true

end if

ActiveDocument.Fields("myFilter").Select ">=" + EndDate.GetContent.String

end sub

Again, I would recommend Rebecca's way using triggers.

Hope this helps!