Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
If I may, let me revisit a chunk of code that I was working through in this post in which I am encountering a new issue.
Please consider this code:
The area in orange is where I'm struggling. The idea is to find the row in which V1 = V2 = V3 from the data in ws_cd within the number of rows in the database defined by variable nrec. There will ALWAYS be ONE match within the data, but each row needs to be stepped through to find it. It can't assume the first instance is the one it's supposed to catch.
In my testing, the first record is matched at row two. A match of pnum in row 2, a match of fac 2 in row 2 and the start time (st) in row 2 = .375 (9:00A). A match! V1=V2=V3 and the appropriate message is displayed.
We step into the next record at row 3. A match of pnum in row 5, a match in fac2 in row 5 but the value of st (.375) is first encountered in row 2! V1=V2<>V3. Their is a message that there is no row matching all three criteria. This is not true. If it didn't accept V3=2 (the first instance of 9:00A) and kept going, it would have discovered that row 5 also contains the value of 9:00A. This would have triggered V1=V2=V3
So, my question is, how do I keep going to find the match. I have to revisit the "Else" code in orange, but honestly, I'm stumped. I'm not even sure I explained myself right, so if not, please ask for clarification.
Please consider this code:
Rich (BB code):
Sub signatures(srow As Integer, pnum As String, fac2 As String, nrec As Long, st As Variant)
'signatures are assigned based on that facility's assigned crew and eligible shift
'this assignmnet, whether a signature is required or not, determines the crew assignemnt of this booking
'srow = the row on the master worksheet being analysed
Dim cd_rrow As Integer 'the row that the current record resides in CORE_DATA
mbevents = False
Stop
'find the row (cd_rrow) in CORE_DATA for which the unique currect booking resides (permit#, facility, and start time)
v1 = Application.WorksheetFunction.Match(pnum, ws_cd.Columns(17), 0) 'returns row number of first match of pnum in column 17 eg 2
v2 = Application.WorksheetFunction.Match(fac2, ws_cd.Columns(6), 0) 'returns row number of first match of pnum in column 6 eg 2
'v3
Dim V As Variant, v3 As Variant
V = ws_cd.Columns(2).Value
'For iv = 1 To UBound(V, 1)
For iv = 2 To nrec
V(iv, 1) = Round(V(iv, 1), 3)
Next iv
v3 = Application.Match(Round(st, 3), V, 0)
If Not IsError(v3) Then
Debug.Print v3
Else
MsgBox "no match in column B"
End If
If v1 = v2 And v1 = v3 Then
cd_rrow = v1
MsgBox "The FIRST row in which all three criteria are satisfied is row : " & cd_rrow
Else
MsgBox "There is no row that match all three criteria."
Stop
End If
'
' Stop
..... unrelated code
mbevents = True
End Sub
The area in orange is where I'm struggling. The idea is to find the row in which V1 = V2 = V3 from the data in ws_cd within the number of rows in the database defined by variable nrec. There will ALWAYS be ONE match within the data, but each row needs to be stepped through to find it. It can't assume the first instance is the one it's supposed to catch.
In my testing, the first record is matched at row two. A match of pnum in row 2, a match of fac 2 in row 2 and the start time (st) in row 2 = .375 (9:00A). A match! V1=V2=V3 and the appropriate message is displayed.
We step into the next record at row 3. A match of pnum in row 5, a match in fac2 in row 5 but the value of st (.375) is first encountered in row 2! V1=V2<>V3. Their is a message that there is no row matching all three criteria. This is not true. If it didn't accept V3=2 (the first instance of 9:00A) and kept going, it would have discovered that row 5 also contains the value of 9:00A. This would have triggered V1=V2=V3
So, my question is, how do I keep going to find the match. I have to revisit the "Else" code in orange, but honestly, I'm stumped. I'm not even sure I explained myself right, so if not, please ask for clarification.