Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

On Demand Webinar: See Why Thousands of QlikView Users Have Switched to Qlik Sense. REGISTER
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro for Clearing selections

Hi all,

I created two sheets namely sheet1 and sheet2. I don't want sheet1 selections to be affected on sheet2 . Here the list box in sheet1 is checked with 'Always one selected value'. 

If I had selected some filters on sheet1 and when I switch to second sheet it should get cleared . At the same time when i come back to sheet1 it should have the same selections .

For this , I used the bookmarks trigger on sheet properties. It leads me to the issue that  whenever I switch from sheet 2 to Sheet1 , It shows me the same selections which created bookmark for the first time.

So, however I managed to write a macro by surfing so many blogs eventhough I am new to macro's section in qlikview.


Sub AlwaysOneSelected
Set QvObj=Activedocument.GetSheetObject("LB28")
Set MyField=QvObj.GetField
Set FieldProp=MyField.GetProperties
MyField.SetProperties FieldProp
End Sub

Sub RemoveOnlyOneSelected
Set QvObj=Activedocument.GetSheetObject("LB28")
Set MyField=QvObj.GetField
Set FieldProp=MyField.GetProperties
MyField.SetProperties FieldProp
ActiveDocument.ClearAll True
End Sub

After writing macro I used the external and Select in field triggers  on sheets but it again leads me to the same issue.

Can someone please help me in correcting this macro ? or any new solution.

Thannks in advance.

PS: I am using qlikview 10 



5 Replies
Not applicable

Whenever I want to Clear a specific Field I use this line of Code.


Not applicable

Thanks for the quick reply Brian.

As I told am new to macro sections. Can you  please tell me clearly?


Not applicable

Here is an Example where I Clear a Field and Toggle a Variable while selecting a new value for that field

Replicating a On / Off State. vOpps is the Variable Name I use to control the If statement or Toggle effect.

The 0 or 1 can be defined any way you want  0 = off

The .Clear is the Method used against the specified field in parens ()


sub ToggleOpps

set v = ActiveDocument.GetVariable("vOpps") 'first create a variable

Cnt= v.getcontent.String

'prop = myobj.GetProperties

if Cnt=0 then


     ActiveDocument.GetField("FlgOpp").Select "0"    'Hide Opps

    v.setContent "1",true    'Hide Opps



     'ActiveDocument.GetField("FlgOpp").Select "1"    'Show Opps

    v.setContent "0",true    'Show Opps


end if

end sub

Contributor II
Contributor II

A great way of starting a clean selection each time you activate a sheet is using Qlikview's built-in 'clear' OnActiveSheet feature. This is not a direct answer to your question, but i note here since its a useful feature. Perhaps the macros are not necessarily needed.

Setting -> Document Properties -> select Sheets tab -> click on the SheetID/Title you want to have cleared on activating -> click on Properties (note -- if you have not selected the sheet you want to apply this to, Properties will be greyed out) -> Click Add Action or Edit Action(s) under 'OnActiveSheet' -> Click Add -> select Action Type 'Selection' and Action 'Clear All'.

Each time you then activate the given Sheet, the 'Current Selections' will be cleared.


How about simply placing the 2 sheets each in a different alternate state ?

This will achieve exactly what you want, as in the selections of the 2 sheets being independent of each other.

It is dead easy to do and avoids messing about with macros which will not work with the Ajax client.