Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
Leverage your QlikView investment to modernize BI – see how! Join Group
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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

Tags (1)
4 Replies
Highlighted
Not applicable

Re: Basic Macro to Set Variable and Select in Field

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.

Highlighted
Not applicable

Re: Basic Macro to Set Variable and Select in Field

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

Highlighted
Not applicable

Re: Basic Macro to Set Variable and Select in Field

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

Specialist II
Specialist II

Re: Basic Macro to Set Variable and Select in Field

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!