ratchet1369
Board Regular
- Joined
- Mar 16, 2009
- Messages
- 58
- Office Version
- 365
- Platform
- Windows
Hey all,
I had a VBA code that was working. It would look for an error condition when Ledger = ABC and Company = V3 and would prompt a message box advising the user "Error on row 20".
They now want to look for company V3 or V4 so I changed the IF into a Case to look for multiple items and now my rowcounter says "Error on row 70", which is the end of the range instead of telling me row 20, which is where the error exists.
Old Code
For rowCounter1 = vCompanyCell.Row To TotalsCell.Row - 1
If (CStr(ws.Cells(rowCounter1, vCompanyCell.Column)) = "V3" And vLedger = "ABC") Then
vResponseCode = -2
gCompanyMsg = "- [Error] Do not use V3 in combination with ABC Ledger, see row " & rowCounter1
End If
New Code
For rowCounter1 = vCompanyCell.Row To TotalsCell.Row - 1
If vLedger = "ABC" Then
Select Case compvalues
Case CStr(ws.Cells(rowCounter1, vCompanyCell.Column)) = "V3", "V4": vResponseCode = -2
End Select
gCompanyMsg = "- [Error] Invalid Company for ABC Ledger, see row " & rowCounter1
End If
Any suggestions on how to direct the user to the row in error?
I had a VBA code that was working. It would look for an error condition when Ledger = ABC and Company = V3 and would prompt a message box advising the user "Error on row 20".
They now want to look for company V3 or V4 so I changed the IF into a Case to look for multiple items and now my rowcounter says "Error on row 70", which is the end of the range instead of telling me row 20, which is where the error exists.
Old Code
For rowCounter1 = vCompanyCell.Row To TotalsCell.Row - 1
If (CStr(ws.Cells(rowCounter1, vCompanyCell.Column)) = "V3" And vLedger = "ABC") Then
vResponseCode = -2
gCompanyMsg = "- [Error] Do not use V3 in combination with ABC Ledger, see row " & rowCounter1
End If
New Code
For rowCounter1 = vCompanyCell.Row To TotalsCell.Row - 1
If vLedger = "ABC" Then
Select Case compvalues
Case CStr(ws.Cells(rowCounter1, vCompanyCell.Column)) = "V3", "V4": vResponseCode = -2
End Select
gCompanyMsg = "- [Error] Invalid Company for ABC Ledger, see row " & rowCounter1
End If
Any suggestions on how to direct the user to the row in error?
Last edited: