Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA testplan loop advice needed

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
I have a loop that makes 25 if then/else checks per row and depending on the data each row can have up to 25 comments added. I now need to test every possible combination from just one of each to all 25 per row (i.e 1, 2, 3,…..1&2, 1&3, 1&4……12&3, 12&4, 12&5, etc.).
I have setup an excel sheet with all 25 conditions listed in cells A1:A25. What I want is a loop that places an X in each column for each test combination, for instance/:
Condition Cell
1 B1
2 C2
3 D3
To
1-25 ?1-?25

This would enable me to keep track of my testing and save a huge amount of time .
Any help will be much appreciated.
Thanks,
Roy
 
If I understand your setup, you want to go through several rows and see if up to 25 conditions are met. Then you want to make some kind of tally (for each row?) of which of the 25 conditions were met?

So let the range of your data be rngData. Then, your primary loop can be something like:
for each r in rngData.rows
next


Now, you could set up an array with 25 elements:
Dim strYN(25) As String
Then, inside the primary loop, you can test each of the 25 conditions:
for i=0 to 24
strYN(i)="N"
if <condition i is met> then strYN(i)="Y"
next


Now you can set the range where the test results go as a column or row, let's say a colum:
set rngRslt=sheet1.range("a1:a25")
Then the array can be dumped to the range:
r.value=strYN

_________________
Bob Rashkin
 
Hi Bob,
I've only just started out in VBA and have yet to use arrays. Also, my row data and condition criteria is from columns A to Z. For instance, row 1: if col A is numeric and col F 3rd character is R then do whatever. This is just 2 conditions but the script needs to report on upto 25 conditions per row.
I have the program written (a feat in itself). All I need now is a way to form a testplan which covers every combination of conditions from 1 of each per row upto all 25 per row.
Surely someone has written a program to create a testplan to follow before now?
Any advice is appreciated.
Thanks,
Roy
 
Hello Knifey,

I'd use the .Offset function of the Range object.
Assuming you're looping through A1:Z1 with a range object, i.e:
For Eeach rngTest in Sheet1.Range("A1:Z1")
'Test here.
Next rngTest

You could add an offset like this:

lngOffset = 1
For Eeach rngTest in Sheet1.Range("A1:Z1")
'Test here.
If TestPassed then
rngTest.Offset(1, 0).value = "X"
End If
'Increment offset before next test.
lngOffset = lngOffset + 1
Next rngTest

If this doesn't help, perhaps you could post some of your source code, so we can see how to help you more effectively.

Hope this helps,

Pete

Hope this helps,
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top