| Forum Home | ||||
| PC World Chat | ||||
| Thread ID: 105557 | 2009-12-06 23:44:00 | Excel VBA - need help | kbp (7436) | PC World Chat |
| Post ID | Timestamp | Content | User | ||
| 836999 | 2009-12-06 23:44:00 | Hi Can someone help me please. I have written this code in Excel VBA (as below) and it's working fine except, it also takes "+" and "-" value in the field. But I only want numeric. I understood that IsNumeric was only for numeric but somehow it considers "+" and "-" as numeric. Does anyone know the solution please or could tell me what I am doing wrong ? Thank you Private Sub CheckTellerValue() If IsNumeric(txtTeller) Then Else sError = sError & vbNewLine & "Personnel Number must be in numeric format." txtTeller.SetFocus End If End Sub |
kbp (7436) | ||
| 837000 | 2009-12-07 18:12:00 | The + or - symbol indicates how far above or below zero the value is, so it is actually part of the number. You have a couple of choices here with the VBA code. You could introduce another test to check for + and - symbols using the instr function, or you could assume the operator intentionally entered the + or - symbol and take the value to another variable after stripping off the sign by using the abs function. Check out the instr and abs functions in your help file, or post back if you get stuck. An alternative approach is to use data validation on the cell(s) in the spreadsheet. Select the cell, select men option Data > Validation > allow whole numbers greater than 0. That may be easier to eliminate the - symbol, but I haven't tested it for the + symbol. Andrew |
andrew93 (249) | ||
| 1 | |||||