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 Advice

Hi guys,

I am writing a macro for the first time and having trouble with it, Please advice

Macro

Sub Test

set mytext = ActiveDocument.GetSheetObject("A").GetCell(0,0)

ActiveDocument.Variables("vTest").SetContent mytext.text, true



set myvar = ActiveDocument.GetSheetObject("B").GetCell(vTest,0)

ActiveDocument.Variables("Test").SetContent mytext2.text, true

End Sub

I am trying to pull a value from sheet object A , store it in a variable vTest and then pass it as a parameter for pulling a value from Sheet object B. The macro above is what i have so far. Please advise,

Can i use a set x = vTest statement of some sort and create a temp variable and use that to get the value from Object B.

Also,

I know what i am trying to maybe easier with a peek function, but i want to be able to keep it dynamic as i have a huge access database linked to my application. Please advice,

Thank you for your time and effort,

Best,

Nik

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

A few minor fixes:

Sub Test

set mytext = ActiveDocument.GetSheetObject("A").GetCell(1,0)
ActiveDocument.Variables("vTest").SetContent mytext.text, true

vt=ActiveDocument.Variables("vTest").GetContent.string
set mytext2 = ActiveDocument.GetSheetObject("B").GetCell(vt,0)
ActiveDocument.Variables("Test").SetContent mytext2.text, true


End Sub

View solution in original post

11 Replies
Anonymous
Not applicable
Author

A few minor fixes:

Sub Test

set mytext = ActiveDocument.GetSheetObject("A").GetCell(1,0)
ActiveDocument.Variables("vTest").SetContent mytext.text, true

vt=ActiveDocument.Variables("vTest").GetContent.string
set mytext2 = ActiveDocument.GetSheetObject("B").GetCell(vt,0)
ActiveDocument.Variables("Test").SetContent mytext2.text, true


End Sub

Not applicable
Author

Thank you Michael for the response.

Best,

Nik

Not applicable
Author

I tried the macro. It works but only upto a specific rowNo after which it gives me an error. Is there a limit on the number the variable can take? (for example: 347 returns an error), My column certainly does have more than 347 rows. Please advice,

Thanks,

Nik

Anonymous
Not applicable
Author

Variable can take anything - number or text.  Wondering if GetCell() has any limits.  Which would be rather strange

Not applicable
Author

That is the exact same reaction i had, get cell is giving me an exception. Do you think its a better idea to use the peek function? Can it be written to dynamically give different values?

Anonymous
Not applicable
Author

I think it is not about limit.  More likely the number you're getting from the object A points you to the row in the object B which doesn't exist.

Not applicable
Author

I will double check the total number of rows for object B. Thanks again.

Anonymous
Not applicable
Author

No Problem.

BTW, I just checked in my sample - it gives error with row 26 in A because it points to row 19 in B, but B has only 18 rows.

On the other hand, it works fine if I read row 1700 from A - it points to row 18 (or 17) in B.

So, it's not the limit.

Not applicable
Author

I understand now, What if i use something like

if(GetSelectedCount(A)>0 , concat(Row No,  ','). will it give me the RowNo from B or just A?