Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro selection of values

I'm sure this question must have been asked before but I cant seem to find an answer. I would like to create a macro that selects all values in a field that are less than the value in an input box. I have created an input box for the user to enter the final day in period and this value then feeds in to a caculated dimension so that the user can see invoice aging as of a specific point in time. I would like to be able to add a macro button that can also select only dates that are less than the value entered in the input box. I have seen many macros where a single value can be selected and a few more that show how to toggle values inside a for next loop but I havent seen anyone using a less than or more than statement in a macro. Is it possible?

Thanks in advance.

1 Solution

Accepted Solutions
Not applicable
Author

The syntax in a macro is similar to what you would use in an Action.

Sub Selector
inputVal = ActiveDocument.Variables("vVar").GetContent.String
ActiveDocument.Fields("FIELD").Select "<" & inputVal
End Sub


For an Input Box with vVar as the variable.

View solution in original post

7 Replies
lblancher
Partner - Contributor III
Partner - Contributor III

You should be able to accomplish this by using actions instead oi macro's. Create a button and add a "selection->select in field" action . This allows you to use the advanced search syntax, where you can use ">" or "<" operators.

Lucas

Not applicable
Author

The syntax in a macro is similar to what you would use in an Action.

Sub Selector
inputVal = ActiveDocument.Variables("vVar").GetContent.String
ActiveDocument.Fields("FIELD").Select "<" & inputVal
End Sub


For an Input Box with vVar as the variable.

Not applicable
Author

As simple as that! Thanks NMillar

Not applicable
Author

I couldnt find how to add the action to a button, Lucas. Is this new in v9? We are still at 8.5 at the moment.

lblancher
Partner - Contributor III
Partner - Contributor III

Yes, you are correct Actions where added to v9.

Lucas

hectorgarcia
Partner - Creator III
Partner - Creator III

what if the field content is not a number, is string,

I.E this can ve a sample of the values:

FIELDnamex
R2968
R2968, R3266, R2344, R35425, R2337, R3553
R3023, R3203
R3084, D19516, D19349, D19442, D19430, D18967, D19523
R3098
R3179
R3221

and you want to search values with 2337 and 3098 or 2968

How the macro will look?

Thanks

Not applicable
Author

First, you need to get your search criteria into a variable. If vTest = 2337, then you can use:

Sub Test
val = ActiveDocument.Variables("vTest").GetContent.String
ActiveDocument.Fields("FIELDNAME").Select "*" & val & "*", true
End Sub


Using wildcards on both sides of the value will look for the search criteria contained anywhere in the value.