Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Value present in a list box or not using Macro

Hi guys

Is it possible to write a macro which checks whether a particular value is present in a list box or not.

For example if i have a list box of country, i want to check whether Australia is present in listbox or not.

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Depending on what you need to do with the result, you can do that within an expression (incl condition display/calculations) and dimensions without resorting to a macro.

Being present in the list box means that it exists in the field. Or do you mean selected in the list box?

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     Find below the macro for the same,

Sub Check

vCheck = 0
set v = ActiveDocument.Variables("vYear")
vYear = v.GetContent.String

set table = ActiveDocument.GetSheetObject( "LB01" )
for RowIter = 0 to table.GetRowCount-1
    for ColIter =0 to table.GetColumnCount-1
        set cell = table.GetCell(RowIter,ColIter)
         if vYear = cell.Text then
           vCheck = 1
         end if
    next
next

if vCheck = 1 then
msgbox "Value Matched"
Else
Msgbox "Value Not Matched"
End if 


End Sub

Here variable vYear is created to take input from user and checking the same value in field.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
sushil353
Master II
Master II

Try this macro:

sub findlistvalue

set table = ActiveDocument.GetSheetObject( "LB08" )

for RowIter = 0 to table.GetRowCount-1

    for ColIter =0 to table.GetColumnCount-1

        set cell = table.GetCell(RowIter,ColIter)

        if(cell.Text="India") Then msgbox(cell.Text)

    next

next

end sub

Note:

Change the "LB08" according to your list value.

HTH

Sushil