PDA

View Full Version : Truncate Data in Excel VBA to prompt Pass or Fail



VBWEE
10-28-2020, 02:08 AM
Hi, I am newbie to Excel VBA
I am need help on VBA to displaying Pass or Fail result in the txtResult box in "Form" tab. And the result should refer to "Data" tab on D column. As there contained excel formula to truncated the entered serial number & check the value in "Ref" tab. Hereby, is there any more simple way to run the formula in VBA? Million Thanks,

Bob Phillips
10-28-2020, 03:28 AM
Your code seems to be writing whatever is entered onto the form onto the Data tab, but your request seems to be asking to get data from that tab? Which is it? Give an example of the form input and t he result that you want to see.

VBWEE
10-28-2020, 05:10 AM
Your code seems to be writing whatever is entered onto the form onto the Data tab, but your request seems to be asking to get data from that tab? Which is it? Give an example of the form input and t he result that you want to see.

Thanks for fast reply.
The Serial number input should be truncated the first 5 digits from left after the entry (After click "Check" button).
Example data: 794901020
After truncated became 79490
This value will use to check not exceed a max & min given Spec (in different sheet). And the given can be change by manually time to time.
Min Value:- 79490
Max Value:- 79989

Expected output Value fall in between Min & Max value. It will shown pass as below image. If value out of this criteria. Result will prompt Fail.

Pass Image
27366
Fail Image
27367

Thanks for your valuable time.

SamT
10-28-2020, 02:49 PM
Dim TruncNo As Long
Dim Passes As Boolean
TruncNo = CLng(Lext(txtSerial, 5))
Passes = (TruncNo >= MinNo And TruncNo <= MaxNo)

Your current Private Sub cmdCheck_Click() code does nothing worthwhile.

VBWEE
10-28-2020, 10:08 PM
Dim TruncNo As Long
Dim Passes As Boolean
TruncNo = CLng(Lext(txtSerial, 5))
Passes = (TruncNo >= MinNo And TruncNo <= MaxNo)

Your current Private Sub cmdCheck_Click() code does nothing worthwhile.


Thanks, SamT
However, I am don't know how to use the function of Lext. It is not working in module.

Bob Phillips
10-29-2020, 04:29 AM
However, I am don't know how to use the function of Lext. It is not working in module.

That should be Left.

SamT
10-29-2020, 10:55 AM
That should be Left.

Thanks. My Keyboard doesn't know how to type