Micro Focus QTP (UFT) Forums
How to give the For Loop for 3 work sheets? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to give the For Loop for 3 work sheets? (/Thread-How-to-give-the-For-Loop-for-3-work-sheets)



How to give the For Loop for 3 work sheets? - Uma - 09-10-2011

Hi,
I am opening a excel sheet from QTP.
This is my following code.
Code:
Set xlWrkbk = xlApp.Workbooks.Open("C:\New Folder\RETS.xls")
Set xlWrksht = xlWrkbk.Worksheets("MD")
Set xlWrksht1 = xlWrkbk.Worksheets("Obj")
Set xlWrksht2 = xlWrkbk.Worksheets("Sea")
'Metadat is the name of the  Excel sheet
intStartRow=1
'Declare the starting row
For intRow = intStartRow to xlWrksht.UsedRange.Rows.Count

Gmd= xlWrksht.Range("A" & intRow)
ID = xlWrksht.Range("B" & intRow)
Format  = xlWrksht.Range("C" & intRow)
Res= xlWrksht1.Range("A" & intRow)
Type1 = xlWrksht1.Range("B" & intRow)
ID1= xlWrksht1.Range("C" & intRow)
...............
Next
In the for loop I am asking to check the rows in the sheet

For
Code:
intRow = intStartRow to xlWrksht.UsedRange.Rows.Count

It checks all the 4 rows and it displays the correct result.

If it work with the 2nd and 3rd sheet it doesnot work properly.
It checks all the rows and again it tries to get inside and
giving invalid procedure call or argument error.

How to solve it?Any idea?

Thanks,
Uma


RE: How to give the For Loop for 3 work sheets? - Uma - 09-10-2011

It is working,I gave 3 forloops based on its worksheet.
Ie 3 forloops based on its worksheet
gav