Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2019, 09:06 AM
Registered User
 
Join Date: Jun 2019
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default 'On Error' not working properly in my Autofilter code

HI There,
I cannot get the 'On error' code work properly in this procedure. Did I enter it in the 'wrong place'?
Thanking you in advance.
( sorry about the formatting, but i do not know how to enter the 'code tags' required to format the code properly.) pls help if you can .
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
 
Old August 15th, 2019, 02:11 PM
Registered User
 
Join Date: Feb 2017
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default 'On Error' not working properly in my Autofilter code

Here is your code in the proper format. You click on the # & then past the code in between the code brackets.
Code:
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
Try it.
The Following User Says Thank You to FrancisM For This Useful Post:
MartinArgimon (August 16th, 2019)
 
Old August 16th, 2019, 09:06 AM
Registered User
 
Join Date: Jun 2019
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Opening Excel 'Buil-in" Data Entry form using VBA code

Many Thanks to FrancisM for sorting out my previous problem regarding 'Autofilter".

I would like to ask one more question if at all possible, please , as follows:

I have decided to use Excel's built-in' Data Entry form ( works perfectly fine for me), although i cannot use it twice ( in other words ) in two separate sheets within the same workbook. The reason is as follows:

I have inserted a Command button to call out the form as follows:
ActiveSheet.ShowDataForm
and then i was told that i had to create a range named 'Database' on that specific sheet to enable the form to open properly. It works fine, although the problem is:

If I want to use Excel's Data Entry form on another sheet of my current workbook, it will not allow me to create another range named 'Database' again.
Hope i explained myself properly.
Can you please assist ?
Thanking you in advance
Regards
Martin Argimon
 
Old August 16th, 2019, 09:20 AM
Registered User
 
Join Date: Feb 2017
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Default Opening Excel 'Buil-in" Data Entry form using VBA code

I am glad that your solution worked for you. I am thinking that excel does not like duplicate names. So just like worksheets, you have to have a different name. I.e when I am calling 2 different web addresses of an site, I use IE1 & IE2. Same site, different names. That is the only solution, I can think of, unless somebody else in the group has a better idea.
 
Old August 16th, 2019, 09:32 AM
Registered User
 
Join Date: Jun 2019
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks FrancisM. Indeed Excel does not like duplicate names that is why i was battling to understand this option, "of calling the Form via VBA and then naming a range 'Database' and not being able to call the Data form on another sheet?
I find it strange that it can only work on one sheet. I shall wait to hear if anybody else has a suggestion
Many thanks again
Kind Regards
Martin Argimon
Kind regards





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web service not working properly in IIS Abhinavnaresh ASP.NET 2.0 Professional 1 April 10th, 2008 08:53 AM
ch 8 code is not working properly Dev_gh78 C# 1 August 4th, 2006 12:16 AM
PreparedStatement not working properly wslyhbb Java Databases 3 September 9th, 2003 01:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.