Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
Hi Folks,
Looking for someone that might be able to provide reason as to why I am getting the wrong result for 'cr' in my code below.
The line highlighted in purple calculates the value of 'cr' by referencing column A of worksheet ws_cd for the value of 'leag'.
When league = "WMSA", the value of CR should be 3. But it's being returned as 4.
In ws_cd, cell A3 = "WMSA" and cell A4 = "WMGSA"
I don't understand why my formula is reporting the wrong value.
Looking for someone that might be able to provide reason as to why I am getting the wrong result for 'cr' in my code below.
The line highlighted in purple calculates the value of 'cr' by referencing column A of worksheet ws_cd for the value of 'leag'.
When league = "WMSA", the value of CR should be 3. But it's being returned as 4.
In ws_cd, cell A3 = "WMSA" and cell A4 = "WMGSA"
I don't understand why my formula is reporting the wrong value.
Rich (BB code):
Sub customer()
Dim cr as long
Dim leag as string
Dim c as double
Stop
mbevents = False
leag = ws_form.Range("K6")
c = Application.WorksheetFunction.CountIf(ws_cd.Columns(1), leag)
ws_form.Unprotect
If c > 1 Then
MsgBox "Error: League has too many entries"
Stop
ElseIf c = 1 Then 'customer info on file
cr = Application.WorksheetFunction.Match(leag, ws_cd.Columns(1))
With ws_form
With .Range("K15, V15")
.Interior.Color = RGB(198, 228, 202)
'.Borders.Color = RGB(55, 86, 35)
If .MergeCells = True Then
Set mergeRange = .MergeArea
mergeRange.Locked = False
End If
End With
.Range("K15").Value = ws_cd.Cells(cr, 2)
.Range("V15") = ws_cd.Cells(cr, 3)
End With
Else
With ws_form.Range("K15")
If .MergeCells = True Then
Set mergeRange = .MergeArea
mergeRange.Locked = False
End If
.Value = ""
.Interior.Color = RGB(221, 235, 247)
'.Borders.Color = RGB(48, 84, 150)
.Select
End With
With ws_form.Range("V15")
If .MergeCells = True Then
Set mergeRange = .MergeArea
mergeRange.Locked = False
End If
.Value = ""
.Interior.Color = RGB(221, 235, 247)
'.Borders.Color = RGB(48, 84, 150)
End With
End If
chg = 0 'user change counter
mbevents = True
End Sub