Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2019, 09:06 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old August 15th, 2019, 02:11 PM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
The Following User Says Thank You to FrancisM For This Useful Post:
MartinArgimon (August 16th, 2019)
  #3 (permalink)  
Old August 16th, 2019, 09:06 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #4 (permalink)  
Old August 16th, 2019, 09:20 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #5 (permalink)  
Old August 16th, 2019, 09:32 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.