Catch user error and re-enable application.events after error
Amateur coder asking for help, again :-)
I have the below code that works good, it gets a variable from a drop down validation list and executes command automatically because I and using the Private Sub Worksheet_Change(ByVal Target As Range). The issue I have is that sometimes the user types into the box rather then select it. 
I get a
run-time error 91
because it cannot find the value typed in by user.
How can I catch this error and make a message popup to tell them they must choose from drop down list? And Also since it breaks the code it sets my Application.EnableEvents to False since it doesn't finish the code from the ByVal Target As Range section that resets to True. 
How can I reset the Application.EnableEvents to True in the event of a code break?
Sub Copy_From_Borrower_DBase()
    Dim myVal As String
    Dim sourceRng As Range
    myVal = Sheets("Main").Range("F2").Value ' dropdown list
    Set sourceRng = Worksheets("Borrower Database").Range("5:5").Find(What:=myVal, LookAt:=xlWhole) 'locate column where to copy from
    Worksheets("Main").Range("F5").Value = Worksheets("Borrower Database").Cells(5, sourceRng.Column).Value 'Borrower Name
    Worksheets("Main").Range("G6").Value = Worksheets("Borrower Database").Cells(6, sourceRng.Column).Value 'Income
End Sub
excel vba excel-vba
add a comment |
Amateur coder asking for help, again :-)
I have the below code that works good, it gets a variable from a drop down validation list and executes command automatically because I and using the Private Sub Worksheet_Change(ByVal Target As Range). The issue I have is that sometimes the user types into the box rather then select it. 
I get a
run-time error 91
because it cannot find the value typed in by user.
How can I catch this error and make a message popup to tell them they must choose from drop down list? And Also since it breaks the code it sets my Application.EnableEvents to False since it doesn't finish the code from the ByVal Target As Range section that resets to True. 
How can I reset the Application.EnableEvents to True in the event of a code break?
Sub Copy_From_Borrower_DBase()
    Dim myVal As String
    Dim sourceRng As Range
    myVal = Sheets("Main").Range("F2").Value ' dropdown list
    Set sourceRng = Worksheets("Borrower Database").Range("5:5").Find(What:=myVal, LookAt:=xlWhole) 'locate column where to copy from
    Worksheets("Main").Range("F5").Value = Worksheets("Borrower Database").Cells(5, sourceRng.Column).Value 'Borrower Name
    Worksheets("Main").Range("G6").Value = Worksheets("Borrower Database").Cells(6, sourceRng.Column).Value 'Income
End Sub
excel vba excel-vba
add a comment |
Amateur coder asking for help, again :-)
I have the below code that works good, it gets a variable from a drop down validation list and executes command automatically because I and using the Private Sub Worksheet_Change(ByVal Target As Range). The issue I have is that sometimes the user types into the box rather then select it. 
I get a
run-time error 91
because it cannot find the value typed in by user.
How can I catch this error and make a message popup to tell them they must choose from drop down list? And Also since it breaks the code it sets my Application.EnableEvents to False since it doesn't finish the code from the ByVal Target As Range section that resets to True. 
How can I reset the Application.EnableEvents to True in the event of a code break?
Sub Copy_From_Borrower_DBase()
    Dim myVal As String
    Dim sourceRng As Range
    myVal = Sheets("Main").Range("F2").Value ' dropdown list
    Set sourceRng = Worksheets("Borrower Database").Range("5:5").Find(What:=myVal, LookAt:=xlWhole) 'locate column where to copy from
    Worksheets("Main").Range("F5").Value = Worksheets("Borrower Database").Cells(5, sourceRng.Column).Value 'Borrower Name
    Worksheets("Main").Range("G6").Value = Worksheets("Borrower Database").Cells(6, sourceRng.Column).Value 'Income
End Sub
excel vba excel-vba
Amateur coder asking for help, again :-)
I have the below code that works good, it gets a variable from a drop down validation list and executes command automatically because I and using the Private Sub Worksheet_Change(ByVal Target As Range). The issue I have is that sometimes the user types into the box rather then select it. 
I get a
run-time error 91
because it cannot find the value typed in by user.
How can I catch this error and make a message popup to tell them they must choose from drop down list? And Also since it breaks the code it sets my Application.EnableEvents to False since it doesn't finish the code from the ByVal Target As Range section that resets to True. 
How can I reset the Application.EnableEvents to True in the event of a code break?
Sub Copy_From_Borrower_DBase()
    Dim myVal As String
    Dim sourceRng As Range
    myVal = Sheets("Main").Range("F2").Value ' dropdown list
    Set sourceRng = Worksheets("Borrower Database").Range("5:5").Find(What:=myVal, LookAt:=xlWhole) 'locate column where to copy from
    Worksheets("Main").Range("F5").Value = Worksheets("Borrower Database").Cells(5, sourceRng.Column).Value 'Borrower Name
    Worksheets("Main").Range("G6").Value = Worksheets("Borrower Database").Cells(6, sourceRng.Column).Value 'Income
End Sub
excel vba excel-vba
excel vba excel-vba
edited Nov 20 '18 at 14:21
Pᴇʜ
23.2k62950
23.2k62950
asked Nov 20 '18 at 13:13
MECMEC
697
697
add a comment |
add a comment |
                                3 Answers
                            3
                        
active
oldest
votes
Check first that the range does not return Nothing (meaning the term was not found). The use of With is basically cosmetic, but I think tidies up the code somewhat.
Sub Copy_From_Borrower_DBase()
Dim myVal As String
Dim sourceRng As Range
myVal = Sheets("Main").Range("F2").Value ' dropdown list
With Worksheets("Borrower Database")
    Set sourceRng = .Range("5:5").Find(What:=myVal, LookAt:=xlWhole)
    If Not sourceRng Is Nothing Then
        Worksheets("Main").Range("F5").Value = .Cells(5, sourceRng.Column).Value 'Borrower Name"
        Worksheets("Main").Range("G6").Value = .Cells(6, sourceRng.Column).Value 'Income"
    Else
        MsgBox "whatever"
    End If
End With
End Sub
 
 
 
 
 
 
 
 this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
 
 – MEC
 Nov 20 '18 at 16:20
 
 
 
 
 
 
 
 
 
 
 Quite possibly. Is this a separate question?
 
 – SJR
 Nov 20 '18 at 16:37
 
 
 
 
 
 
 
 
 
 
 Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
 
 – MEC
 Nov 20 '18 at 16:52
 
 
 
 
 
 
 
 
 
 
 Yes, I think that's probably best if you are asking a whole new question. Thanks.
 
 – SJR
 Nov 20 '18 at 17:07
 
 
 
 
 
 
 
 
 
 
 Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
 
 – Tom
 Nov 20 '18 at 17:57
 
 
 
 
 
|
show 1 more comment
To answer the question about error handling:
Public Sub MyProcedure()
    Application.EnableEvents = False
    On Error Goto ENABLE_EVENTS 'if any error occurs after this line events get enabled.
    'stuff where an error could occur
ENABLE_EVENTS:
    Application.EnableEvents = True
    If Err.Number <> 0 Then
        MsgBox "an error occurred"
    End If
End Sub
For more information about error handling: VBA Error Handling – A Complete Guide.
 
 
 
 
 
 
 
 Where do I place this code and do I have to call it from every Sub?
 
 – MEC
 Nov 20 '18 at 16:12
 
 
 
 
 
 
 
 
 
 
 Everything you need to know about error handling is in that guide. Actually this is an example how you can use- EnableEvents = Falsein your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.
 
 – Pᴇʜ
 Nov 21 '18 at 7:00
 
 
 
 
 
add a comment |
I would first try to solve the problem by not allowing there to be a problem, if that fails then worry about error handling.
Since you are already calling Worksheet_Change and using Data Validation, this checks the value of the validation cell. If it has a value in it then your code will run. If it is empty it will not. Data Validation clears the cell if someone types in it, so no matter what they type by the time it hits Worksheet_Change it should be an empty string.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$2" Then         ' Your Dropdown Validation Cell
        If Not Target.Value = "" Then
            Call Copy_From_Borrower_DBase
        End If
    End If
End Sub
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393809%2fcatch-user-error-and-re-enable-application-events-after-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
                                3 Answers
                            3
                        
active
oldest
votes
                                3 Answers
                            3
                        
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check first that the range does not return Nothing (meaning the term was not found). The use of With is basically cosmetic, but I think tidies up the code somewhat.
Sub Copy_From_Borrower_DBase()
Dim myVal As String
Dim sourceRng As Range
myVal = Sheets("Main").Range("F2").Value ' dropdown list
With Worksheets("Borrower Database")
    Set sourceRng = .Range("5:5").Find(What:=myVal, LookAt:=xlWhole)
    If Not sourceRng Is Nothing Then
        Worksheets("Main").Range("F5").Value = .Cells(5, sourceRng.Column).Value 'Borrower Name"
        Worksheets("Main").Range("G6").Value = .Cells(6, sourceRng.Column).Value 'Income"
    Else
        MsgBox "whatever"
    End If
End With
End Sub
 
 
 
 
 
 
 
 this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
 
 – MEC
 Nov 20 '18 at 16:20
 
 
 
 
 
 
 
 
 
 
 Quite possibly. Is this a separate question?
 
 – SJR
 Nov 20 '18 at 16:37
 
 
 
 
 
 
 
 
 
 
 Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
 
 – MEC
 Nov 20 '18 at 16:52
 
 
 
 
 
 
 
 
 
 
 Yes, I think that's probably best if you are asking a whole new question. Thanks.
 
 – SJR
 Nov 20 '18 at 17:07
 
 
 
 
 
 
 
 
 
 
 Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
 
 – Tom
 Nov 20 '18 at 17:57
 
 
 
 
 
|
show 1 more comment
Check first that the range does not return Nothing (meaning the term was not found). The use of With is basically cosmetic, but I think tidies up the code somewhat.
Sub Copy_From_Borrower_DBase()
Dim myVal As String
Dim sourceRng As Range
myVal = Sheets("Main").Range("F2").Value ' dropdown list
With Worksheets("Borrower Database")
    Set sourceRng = .Range("5:5").Find(What:=myVal, LookAt:=xlWhole)
    If Not sourceRng Is Nothing Then
        Worksheets("Main").Range("F5").Value = .Cells(5, sourceRng.Column).Value 'Borrower Name"
        Worksheets("Main").Range("G6").Value = .Cells(6, sourceRng.Column).Value 'Income"
    Else
        MsgBox "whatever"
    End If
End With
End Sub
 
 
 
 
 
 
 
 this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
 
 – MEC
 Nov 20 '18 at 16:20
 
 
 
 
 
 
 
 
 
 
 Quite possibly. Is this a separate question?
 
 – SJR
 Nov 20 '18 at 16:37
 
 
 
 
 
 
 
 
 
 
 Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
 
 – MEC
 Nov 20 '18 at 16:52
 
 
 
 
 
 
 
 
 
 
 Yes, I think that's probably best if you are asking a whole new question. Thanks.
 
 – SJR
 Nov 20 '18 at 17:07
 
 
 
 
 
 
 
 
 
 
 Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
 
 – Tom
 Nov 20 '18 at 17:57
 
 
 
 
 
|
show 1 more comment
Check first that the range does not return Nothing (meaning the term was not found). The use of With is basically cosmetic, but I think tidies up the code somewhat.
Sub Copy_From_Borrower_DBase()
Dim myVal As String
Dim sourceRng As Range
myVal = Sheets("Main").Range("F2").Value ' dropdown list
With Worksheets("Borrower Database")
    Set sourceRng = .Range("5:5").Find(What:=myVal, LookAt:=xlWhole)
    If Not sourceRng Is Nothing Then
        Worksheets("Main").Range("F5").Value = .Cells(5, sourceRng.Column).Value 'Borrower Name"
        Worksheets("Main").Range("G6").Value = .Cells(6, sourceRng.Column).Value 'Income"
    Else
        MsgBox "whatever"
    End If
End With
End Sub
Check first that the range does not return Nothing (meaning the term was not found). The use of With is basically cosmetic, but I think tidies up the code somewhat.
Sub Copy_From_Borrower_DBase()
Dim myVal As String
Dim sourceRng As Range
myVal = Sheets("Main").Range("F2").Value ' dropdown list
With Worksheets("Borrower Database")
    Set sourceRng = .Range("5:5").Find(What:=myVal, LookAt:=xlWhole)
    If Not sourceRng Is Nothing Then
        Worksheets("Main").Range("F5").Value = .Cells(5, sourceRng.Column).Value 'Borrower Name"
        Worksheets("Main").Range("G6").Value = .Cells(6, sourceRng.Column).Value 'Income"
    Else
        MsgBox "whatever"
    End If
End With
End Sub
answered Nov 20 '18 at 13:24
SJRSJR
12.9k31217
12.9k31217
 
 
 
 
 
 
 
 this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
 
 – MEC
 Nov 20 '18 at 16:20
 
 
 
 
 
 
 
 
 
 
 Quite possibly. Is this a separate question?
 
 – SJR
 Nov 20 '18 at 16:37
 
 
 
 
 
 
 
 
 
 
 Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
 
 – MEC
 Nov 20 '18 at 16:52
 
 
 
 
 
 
 
 
 
 
 Yes, I think that's probably best if you are asking a whole new question. Thanks.
 
 – SJR
 Nov 20 '18 at 17:07
 
 
 
 
 
 
 
 
 
 
 Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
 
 – Tom
 Nov 20 '18 at 17:57
 
 
 
 
 
|
show 1 more comment
 
 
 
 
 
 
 
 this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
 
 – MEC
 Nov 20 '18 at 16:20
 
 
 
 
 
 
 
 
 
 
 Quite possibly. Is this a separate question?
 
 – SJR
 Nov 20 '18 at 16:37
 
 
 
 
 
 
 
 
 
 
 Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
 
 – MEC
 Nov 20 '18 at 16:52
 
 
 
 
 
 
 
 
 
 
 Yes, I think that's probably best if you are asking a whole new question. Thanks.
 
 – SJR
 Nov 20 '18 at 17:07
 
 
 
 
 
 
 
 
 
 
 Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
 
 – Tom
 Nov 20 '18 at 17:57
 
 
 
 
 
this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
– MEC
Nov 20 '18 at 16:20
this worked great, can you help me with code to see if record exists and if so a msgbox to indicate YES or NO?
– MEC
Nov 20 '18 at 16:20
Quite possibly. Is this a separate question?
– SJR
Nov 20 '18 at 16:37
Quite possibly. Is this a separate question?
– SJR
Nov 20 '18 at 16:37
Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
– MEC
Nov 20 '18 at 16:52
Ummm yeah I guess it is, should I post a new question? and mark this one as answered by you?
– MEC
Nov 20 '18 at 16:52
Yes, I think that's probably best if you are asking a whole new question. Thanks.
– SJR
Nov 20 '18 at 17:07
Yes, I think that's probably best if you are asking a whole new question. Thanks.
– SJR
Nov 20 '18 at 17:07
Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
– Tom
Nov 20 '18 at 17:57
Whilst this may handle the error it doesn't really answer the question on how to catch the error and how to re-enable events after
– Tom
Nov 20 '18 at 17:57
|
show 1 more comment
To answer the question about error handling:
Public Sub MyProcedure()
    Application.EnableEvents = False
    On Error Goto ENABLE_EVENTS 'if any error occurs after this line events get enabled.
    'stuff where an error could occur
ENABLE_EVENTS:
    Application.EnableEvents = True
    If Err.Number <> 0 Then
        MsgBox "an error occurred"
    End If
End Sub
For more information about error handling: VBA Error Handling – A Complete Guide.
 
 
 
 
 
 
 
 Where do I place this code and do I have to call it from every Sub?
 
 – MEC
 Nov 20 '18 at 16:12
 
 
 
 
 
 
 
 
 
 
 Everything you need to know about error handling is in that guide. Actually this is an example how you can use- EnableEvents = Falsein your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.
 
 – Pᴇʜ
 Nov 21 '18 at 7:00
 
 
 
 
 
add a comment |
To answer the question about error handling:
Public Sub MyProcedure()
    Application.EnableEvents = False
    On Error Goto ENABLE_EVENTS 'if any error occurs after this line events get enabled.
    'stuff where an error could occur
ENABLE_EVENTS:
    Application.EnableEvents = True
    If Err.Number <> 0 Then
        MsgBox "an error occurred"
    End If
End Sub
For more information about error handling: VBA Error Handling – A Complete Guide.
 
 
 
 
 
 
 
 Where do I place this code and do I have to call it from every Sub?
 
 – MEC
 Nov 20 '18 at 16:12
 
 
 
 
 
 
 
 
 
 
 Everything you need to know about error handling is in that guide. Actually this is an example how you can use- EnableEvents = Falsein your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.
 
 – Pᴇʜ
 Nov 21 '18 at 7:00
 
 
 
 
 
add a comment |
To answer the question about error handling:
Public Sub MyProcedure()
    Application.EnableEvents = False
    On Error Goto ENABLE_EVENTS 'if any error occurs after this line events get enabled.
    'stuff where an error could occur
ENABLE_EVENTS:
    Application.EnableEvents = True
    If Err.Number <> 0 Then
        MsgBox "an error occurred"
    End If
End Sub
For more information about error handling: VBA Error Handling – A Complete Guide.
To answer the question about error handling:
Public Sub MyProcedure()
    Application.EnableEvents = False
    On Error Goto ENABLE_EVENTS 'if any error occurs after this line events get enabled.
    'stuff where an error could occur
ENABLE_EVENTS:
    Application.EnableEvents = True
    If Err.Number <> 0 Then
        MsgBox "an error occurred"
    End If
End Sub
For more information about error handling: VBA Error Handling – A Complete Guide.
answered Nov 20 '18 at 14:27
PᴇʜPᴇʜ
23.2k62950
23.2k62950
 
 
 
 
 
 
 
 Where do I place this code and do I have to call it from every Sub?
 
 – MEC
 Nov 20 '18 at 16:12
 
 
 
 
 
 
 
 
 
 
 Everything you need to know about error handling is in that guide. Actually this is an example how you can use- EnableEvents = Falsein your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.
 
 – Pᴇʜ
 Nov 21 '18 at 7:00
 
 
 
 
 
add a comment |
 
 
 
 
 
 
 
 Where do I place this code and do I have to call it from every Sub?
 
 – MEC
 Nov 20 '18 at 16:12
 
 
 
 
 
 
 
 
 
 
 Everything you need to know about error handling is in that guide. Actually this is an example how you can use- EnableEvents = Falsein your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.
 
 – Pᴇʜ
 Nov 21 '18 at 7:00
 
 
 
 
 
Where do I place this code and do I have to call it from every Sub?
– MEC
Nov 20 '18 at 16:12
Where do I place this code and do I have to call it from every Sub?
– MEC
Nov 20 '18 at 16:12
Everything you need to know about error handling is in that guide. Actually this is an example how you can use
EnableEvents = False in your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.– Pᴇʜ
Nov 21 '18 at 7:00
Everything you need to know about error handling is in that guide. Actually this is an example how you can use
EnableEvents = False in your procedure and ensure it will always be re-enabled if an error occurs. That's nothing you can call from your sub, that's a how you do it in your sub.– Pᴇʜ
Nov 21 '18 at 7:00
add a comment |
I would first try to solve the problem by not allowing there to be a problem, if that fails then worry about error handling.
Since you are already calling Worksheet_Change and using Data Validation, this checks the value of the validation cell. If it has a value in it then your code will run. If it is empty it will not. Data Validation clears the cell if someone types in it, so no matter what they type by the time it hits Worksheet_Change it should be an empty string.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$2" Then         ' Your Dropdown Validation Cell
        If Not Target.Value = "" Then
            Call Copy_From_Borrower_DBase
        End If
    End If
End Sub
add a comment |
I would first try to solve the problem by not allowing there to be a problem, if that fails then worry about error handling.
Since you are already calling Worksheet_Change and using Data Validation, this checks the value of the validation cell. If it has a value in it then your code will run. If it is empty it will not. Data Validation clears the cell if someone types in it, so no matter what they type by the time it hits Worksheet_Change it should be an empty string.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$2" Then         ' Your Dropdown Validation Cell
        If Not Target.Value = "" Then
            Call Copy_From_Borrower_DBase
        End If
    End If
End Sub
add a comment |
I would first try to solve the problem by not allowing there to be a problem, if that fails then worry about error handling.
Since you are already calling Worksheet_Change and using Data Validation, this checks the value of the validation cell. If it has a value in it then your code will run. If it is empty it will not. Data Validation clears the cell if someone types in it, so no matter what they type by the time it hits Worksheet_Change it should be an empty string.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$2" Then         ' Your Dropdown Validation Cell
        If Not Target.Value = "" Then
            Call Copy_From_Borrower_DBase
        End If
    End If
End Sub
I would first try to solve the problem by not allowing there to be a problem, if that fails then worry about error handling.
Since you are already calling Worksheet_Change and using Data Validation, this checks the value of the validation cell. If it has a value in it then your code will run. If it is empty it will not. Data Validation clears the cell if someone types in it, so no matter what they type by the time it hits Worksheet_Change it should be an empty string.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$2" Then         ' Your Dropdown Validation Cell
        If Not Target.Value = "" Then
            Call Copy_From_Borrower_DBase
        End If
    End If
End Sub
edited Nov 20 '18 at 18:56
answered Nov 20 '18 at 16:53
JosephCJosephC
62310
62310
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393809%2fcatch-user-error-and-re-enable-application-events-after-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown