Free Excel VBA Course #22 - Error Handling in VBA (On Error Goto/Resume)
ฝัง
- เผยแพร่เมื่อ 24 ก.ย. 2024
- In this video, I will show you how to handle errors in VBA in Excel.
VBA has given us some tools and techniques you can use to handle errors and In some cases use these to your advantage.
There are statements such as On Error Goto or On Error Resume where you can specify what to do in case VBA encounters an error. You can ask the code to jump to a specific line of code or you can ask it to ignore the error and keep moving.
You can also use message boxes to identify and understand the errors better.
✅ VBA Course Download files: trumpexcel.com...
☕ If you find my Excel videos useful and would like to support me, you can buy me a coffee - www.buymeacoff...
Free Excel Course (Basic to Advanced) - trumpexcel.com...
Best Excel Books: trumpexcel.com...
Subscribe to get awesome Excel Tips every week: www.youtube.co...
#Excel #ExcelTips #ExcelTutorial
Thank you for the interesting Video
Very helpful and concise! Thank you!
This is amazing. Has saved me so much pain. Thank you so much
very comprehensive, thank you!
Thank you it helped me a lot.
Thanks so much.
Perfect for me
It helped me a lot, thank you
Awesome video 👍
Nice video
thank you
Great effort
Thank you!
amazing sir thankx 👍👍👍👍👍👍👍
how to exit the loop? I have no idea. Eventually i had to end the task via taskmanager. Any feedback is highly appreciated.
👍👍👍👍👍
can i handle "runtime error 4605" with this method?
Can you help me what i am missing out in this code? after debugging showing run time error 13 "Number = InputBox("Enter numeric value")" area
Sub errorhandling()
Dim Number As Long
On Error GoTo EntryError
Number = InputBox("Enter numeric value")
Range("A1").Value = Number
EntryError:
MsgBox "Please enter valid value"
End Sub
It's working fine. You should try in a new file.
In the following, when i run it, it takes alphanumeric value, numeric value, integer value. It didn't show error.
Can anyone give me what I have done wrong?
Sub ErrorHandling()
Dim Emp_Name As String
EName:
On Error GoTo NameError
Emp_Name = InputBox("Please Enter Employee Name")
Range("b2") = Emp_Name
Exit Sub
NameError:
MsgBox "Please Enter Numeric Value Only"
Resume EName
End Sub
I think you need to put '.Value' after the Range("B2").
@@andrewtuinkwtuink I also used ".value" but same error
@@umamaheshk6151 Employee name supposed to be Alphabeth right? String could handle alphabeth and number. If You want number only, You could use long.
If this still give different results, wish someone notice this and give the right answer.
@@andrewtuinkwtuink Yes. But I want only alphabets in Name, then what I have to do?
@@umamaheshk6151 This solution from Warship at mrexcel
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii < 65 Or KeyAscii > 90) And (KeyAscii < 97 Or KeyAscii > 122) Then KeyAscii = 0
End Sub