MartinArgimon
New Member
- Joined
- Jun 23, 2019
- Messages
- 8
HI There,
My code does NOT stop with the "On Error...." code, when i type a 'non-existant' order number. It does not take my back to "Re-try".
Do i have the "On error..." code in the wrong slot within the overall code of the procedure?
See below.
Many thanks
Private Sub CmdbuttonPurchaseSummary_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Beneficiaries_Burials")
Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Purchase_Summary")
Dim ordernumber As Integer
'TryAgain:
ordernumber = Application.InputBox(Prompt:="Enter Order Number", Type:=1)
dsh.Range("C21:R400").ClearContents
sh.Activate
sh.AutoFilterMode = False
'On Error GoTo TryAgain
sh.Range("Beneficiaries_Burials").AutoFilter Field:=1, Criteria1:=ordernumber
'On Error GoTo 0
sh.Range("Beneficiaries_Burials").Copy
dsh.Activate
dsh.Range("C11").Value = ordernumber
dsh.Range("C21").PasteSpecial xlPasteValues
sh.AutoFilterMode = False
sh.ShowAllData
'Exit Sub
'TryAgain:
' MsgBox "you have entered the wrong Order Number"
End Sub
My code does NOT stop with the "On Error...." code, when i type a 'non-existant' order number. It does not take my back to "Re-try".
Do i have the "On error..." code in the wrong slot within the overall code of the procedure?
See below.
Many thanks
Private Sub CmdbuttonPurchaseSummary_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Beneficiaries_Burials")
Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Purchase_Summary")
Dim ordernumber As Integer
'TryAgain:
ordernumber = Application.InputBox(Prompt:="Enter Order Number", Type:=1)
dsh.Range("C21:R400").ClearContents
sh.Activate
sh.AutoFilterMode = False
'On Error GoTo TryAgain
sh.Range("Beneficiaries_Burials").AutoFilter Field:=1, Criteria1:=ordernumber
'On Error GoTo 0
sh.Range("Beneficiaries_Burials").Copy
dsh.Activate
dsh.Range("C11").Value = ordernumber
dsh.Range("C21").PasteSpecial xlPasteValues
sh.AutoFilterMode = False
sh.ShowAllData
'Exit Sub
'TryAgain:
' MsgBox "you have entered the wrong Order Number"
End Sub