vTask Boards >> Sample vTask Scripts (Basic) >> Loop thru cells in an Excel spreadsheet
Message started by vTask Support on Jan 8th, 2009 at 5:37pm
Title: Loop thru cells in an Excel spreadsheet
Post by vTask Support on Jan 8th, 2009 at 5:37pm
You can iterate through each cell in a spreadsheet with a loop. This loop can move vertically, horizontally, in reverse, or any way that you need to parse Excel data. This has many useful purposes, such as updating monthly data, or performing a data-driven test script.
For our example, we will use the following spreadsheet:
To loop through the "A1-A3" cells (vertically), the following script will work:
To loop through the "A1-C1" cells (horizontally), it takes a little more work, since we want to increment the Cell Columns (letters), not the row numbers. The following script will work:
Be sure to update for the correct location of "Book1.xls" on your PC.
Title: Re: Loop thru cells in an Excel spreadsheet
Post by vTask Support on Aug 18th, 2009 at 8:30am
Additional note: To determine the total number of cells or rows, use the "Get Cell Format" command under the Excel category, and use the Total Rows or Total Columns option.
Below is a short demo which returns the number of columns. To return the Row count, simply change the option to "Total Rows."
When running the sample below, be sure to update for the appropriate location for "Book1.xls".
vTask Forum » Powered by YaBB 2.4!
YaBB © 2000-2009. All Rights Reserved.