Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro - Loop Through Table

I need a sample macro that loops thorugh a table and reads out some values.  I can't find one.  

1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

You just need to specify the column index (starting at zero for column 1) so looping through values in the first column would need...

          set cell = TableBox.GetCell(RowIter,0)

flipside

View solution in original post

6 Replies
flipside
Partner - Specialist II
Partner - Specialist II

Hi,

From API Guide.qvw ...

set TableBox = ActiveDocument.GetSheetObject( "TB01" )

for RowIter = 0 to TableBox.GetRowCount-1

    for ColIter =0 to TableBox.GetColumnCount-1

        set cell = TableBox.GetCell(RowIter,ColIter)

        msgbox(cell.Text)

    next

next

flipside

Not applicable
Author

Hi flipside

Where in the API did you get this? The Automation Examples sheet? If so, what search did you do on member?

flipside
Partner - Specialist II
Partner - Specialist II

Hi Ian,

I'm working in QV10 and got it from ...

Class = TableBox

Member = GetCell

...  showing as introduced in 6.0x.

flipside

Not applicable
Author

If I don't want to loop through each column but just get a value from one column how would i do that? 

set TableBox = ActiveDocument.GetSheetObject( "tb_emails_to_send" )

    for RowIter = 0 to TableBox.GetRowCount-1   

        set cell = ?

        msgbox(cell.Text)   

    next

Not applicable
Author

This code moves from column to column and row to row and keepings counting. It gets the value in the 16th spot in the loop and puts into the variable vValue and exits the sub routine.

hths,

Stephen

sub ParetoCountInvValue1

vCounter1 = 0

vCounter2 = 0

set table = ActiveDocument.GetSheetObject( "CH01" )

for RowIter = 0 to table.GetRowCount-1

for ColIter =0 to table.GetColumnCount-1

set cell = table.GetCell(RowIter,ColIter)

vCounter1 = vCounter1 + 1

if vCounter1 = 16 then

'msgbox ColIter

'msgbox(cell.Text)

set v = ActiveDocument.Variables("vValue")

v.SetContent cell.Text,true

exit sub

else

end if

next

next

end sub

flipside
Partner - Specialist II
Partner - Specialist II

You just need to specify the column index (starting at zero for column 1) so looping through values in the first column would need...

          set cell = TableBox.GetCell(RowIter,0)

flipside