I've got some QA testcases in a spreadsheet. The tests are separated into different sub-sections on each sheet (as well as different major sections on different worksheets). Column B contains the test numbers like this:
Column F holds the pass/fail ('P' or 'F') for each test.
Currently my code will detect a change in column F and update a summary at the beginning of each section of the number of pass/fail tests for each sub-section.
However, the start and end row numbers for each sub-section are hardcoded for now, which means if I insert or delete a test, I'll have to remember to update all the hardcoded row numbers in the macro too. Here is an example:
I'd like to find a way for the start & end row numbers to be dynamically passed to my PassFail() function. So far the only thing I've been able to think of is to look at Column B of the same row where the change happened, parse out the first number of the test number, then move through all rows in Column B to find out where the start and end rows are...
Before spending too much time coding & debugging that logic, I was wondering if anyone has any better solutions?
Code:
1
1.1
1.2
1.2.1
1.3
2
2.1
2.1.1
2.2
...
Column F holds the pass/fail ('P' or 'F') for each test.
Currently my code will detect a change in column F and update a summary at the beginning of each section of the number of pass/fail tests for each sub-section.
However, the start and end row numbers for each sub-section are hardcoded for now, which means if I insert or delete a test, I'll have to remember to update all the hardcoded row numbers in the macro too. Here is an example:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 6 Then
ADDBUSER.First = 4
ADDBUSER.Last = 125
ALTBUSER.First = 127
ALTBUSER.Last = 257
DELBUSER.First = 298
DELBUSER.Last = 265
LSTBUSER.First = 287
LSTBUSER.Last = 281
ALTKN.First = 283
ALTKN.Last = 337
LTKN.First = 339
LTKN.Last = 415
DTKN.First = 417
DTKN.Last = 484
BLKTEST.First = 486
BLKTEST.Last = 501
RBALTBSE.First = 503
RBALTBSE.Last = 629
RBDEFBSE.First = 631
RBDEFBSE.Last = 759
RBDELBSE.First = 761
RBDELBSE.Last = 797
RBLISTBSE.First = 780
RBLISTBSE.Last = 811
'Pass the correct beginning and end row # for the test group.
If Target.row >= ADDBUSER.First And Target.row <= ADDBUSER.Last Then
Call PassFail(Sheets(Target.Parent.Name), ADDBUSER.First, ADDBUSER.Last)
ElseIf Target.row >= ALTBUSER.First And Target.row <= ALTBUSER.Last Then
Call PassFail(Sheets(Target.Parent.Name), ALTBUSER.First, ALTBUSER.Last)
ElseIf Target.row >= DELBUSER.First And Target.row <= DELBUSER.Last Then
Call PassFail(Sheets(Target.Parent.Name), DELBUSER.First, DELBUSER.Last)
ElseIf Target.row >= LSTBUSER.First And Target.row <= LSTBUSER.Last Then
Call PassFail(Sheets(Target.Parent.Name), LSTBUSER.First, LSTBUSER.Last)
ElseIf Target.row >= ALTKN.First And Target.row <= ALTKN.Last Then
Call PassFail(Sheets(Target.Parent.Name), ALTKN.First, ALTKN.Last)
ElseIf Target.row >= LTKN.First And Target.row <= LTKN.Last Then
Call PassFail(Sheets(Target.Parent.Name), LTKN.First, LTKN.Last)
ElseIf Target.row >= DTKN.First And Target.row <= DTKN.Last Then
Call PassFail(Sheets(Target.Parent.Name), DTKN.First, DTKN.Last)
ElseIf Target.row >= BLKTEST.First And Target.row <= BLKTEST.Last Then
Call PassFail(Sheets(Target.Parent.Name), BLKTEST.First, BLKTEST.Last)
ElseIf Target.row >= RBALTBSE.First And Target.row <= RBALTBSE.Last Then
Call PassFail(Sheets(Target.Parent.Name), RBALTBSE.First, RBALTBSE.Last)
ElseIf Target.row >= RBDEFBSE.First And Target.row <= RBDEFBSE.Last Then
Call PassFail(Sheets(Target.Parent.Name), RBDEFBSE.First, RBDEFBSE.Last)
ElseIf Target.row >= RBDELBSE.First And Target.row <= RBDELBSE.Last Then
Call PassFail(Sheets(Target.Parent.Name), RBDELBSE.First, RBDELBSE.Last)
ElseIf Target.row >= RBLISTBSE.First And Target.row <= RBLISTBSE.Last Then
Call PassFail(Sheets(Target.Parent.Name), RBLISTBSE.First, RBLISTBSE.Last)
ElseIf Target.row >= RBALTBSE.First And Target.row <= RBALTBSE.Last Then
Call PassFail(Sheets(Target.Parent.Name), RBALTBSE.First, RBALTBSE.Last)
ElseIf Target.row > RBALTBSE.Last Then
MsgBox ("Please update the macro. I don't know how to calculate that line yet!")
End If
End If
End Sub
I'd like to find a way for the start & end row numbers to be dynamically passed to my PassFail() function. So far the only thing I've been able to think of is to look at Column B of the same row where the change happened, parse out the first number of the test number, then move through all rows in Column B to find out where the start and end rows are...
Before spending too much time coding & debugging that logic, I was wondering if anyone has any better solutions?