Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2012, 10:10 AM
excelledsoftware excelledsoftware is offline Message Box Restriction Windows 7 64bit Message Box Restriction Office 2003
IT Specialist
Message Box Restriction
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default Message Box Restriction

Hello,



I have a pivot table to where i want to control a field with macro. Specifically an input box that is dimmed as a string or integer. I have gotten this far but the problem is if the user types something into the input box that is not a valid field it overrides it. Basically how do I restrict a user from accepting anything into an input box that is not a number or how do I constrict it to a specific list in a table.

Thanks
Reply With Quote
  #2  
Old 03-22-2012, 10:30 AM
Catalin.B Catalin.B is offline Message Box Restriction Windows Vista Message Box Restriction Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

I do not know how your macro looks, but basically, there is a difference between InputBox and Application.InputBox. (I guess you use the first one )
With the last one, you can select the type of data permitted for an entry:
Type:=0 A formula
Type:=1 A number
Type:=2 Text (a string)
Type:=4 A logical value (True or False)
Type:=8 A cell reference, as a Range object
Type:=16 An error value, such as #N/A
Type:=64 An array of values
Code:
Application.InputBox("Enter a number !", Title:="Numbers", Default:=1, Type:=1)
And, as you can see, you can enter a default value if you need that...
Reply With Quote
  #3  
Old 03-22-2012, 10:38 AM
excelledsoftware excelledsoftware is offline Message Box Restriction Windows 7 64bit Message Box Restriction Office 2003
IT Specialist
Message Box Restriction
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Quote:
Originally Posted by Catalin.B View Post
I do not know how your macro looks, but basically, there is a difference between InputBox and Application.InputBox. (I guess you use the first one )
With the last one, you can select the type of data permitted for an entry:
Type:=0 A formula
Type:=1 A number
Type:=2 Text (a string)
Type:=4 A logical value (True or False)
Type:=8 A cell reference, as a Range object
Type:=16 An error value, such as #N/A
Type:=64 An array of values
Code:
Application.InputBox("Enter a number !", Title:="Numbers", Default:=1, Type:=1)
And, as you can see, you can enter a default value if you need that...
Ah, Yes I was using the first one. Here is what my macro looks like right now.

Sub RefreshSelect()
'
' RefreshSelect Macro
' Macro recorded 3/22/2012 by JRErickson
ActiveSheet.PivotTables("PivotTable6").PivotCache. Refresh
Dim Tablenum As Integer
Tablenum = Application.InputBox("Enter Old Style Division Number", Title:="Numbers", Default:=1, Type:=1)
ActiveSheet.PivotTables("PivotTable6").PivotFields ("DIV").CurrentPage = Tablenum
End Sub

Now I just need to restrict it to a list found on another worksheet. Where does that go? in the title?
Reply With Quote
  #4  
Old 03-22-2012, 11:06 AM
Catalin.B Catalin.B is offline Message Box Restriction Windows Vista Message Box Restriction Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

For selecting a value from a list, is better to create a form, with a list field, you can find here lots of examples. If you cannot find one, i will give you tomorrow an example.
Reply With Quote
  #5  
Old 03-22-2012, 11:12 AM
excelledsoftware excelledsoftware is offline Message Box Restriction Windows 7 64bit Message Box Restriction Office 2003
IT Specialist
Message Box Restriction
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Quote:
Originally Posted by Catalin.B View Post
For selecting a value from a list, is better to create a form, with a list field, you can find here lots of examples. If you cannot find one, i will give you tomorrow an example.
Hmmmn Ive allready got that with the Pivot Table. Oh well my goal was to have the user type in a number from 1-9 (6 is not always a valid number though) and it restrict them to that. The reason I wanted it as a macro was so the pivot table will refresh each time they click it.
Reply With Quote
  #6  
Old 03-22-2012, 11:17 AM
Catalin.B Catalin.B is offline Message Box Restriction Windows Vista Message Box Restriction Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Why don't you give all the details from the begining?
All you need to do is to insert a validation line:
Code:
Tablenum = Application.InputBox("Enter Old Style Division Number, a number from 1 to 9:", Title:="Numbers", Default:=1, Type:=1)
If Tablenum < 1 Or Tablenum > 9 then 
MsgBox "Not valid!"
Exit Sub
End if
ActiveSheet.PivotTables("PivotTable6").PivotFields  ("DIV").CurrentPage = Tablenum
Reply With Quote
  #7  
Old 03-22-2012, 12:08 PM
excelledsoftware excelledsoftware is offline Message Box Restriction Windows 7 64bit Message Box Restriction Office 2003
IT Specialist
Message Box Restriction
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Quote:
Originally Posted by Catalin.B View Post
Why don't you give all the details from the begining?
All you need to do is to insert a validation line:
Code:
Tablenum = Application.InputBox("Enter Old Style Division Number, a number from 1 to 9:", Title:="Numbers", Default:=1, Type:=1)
If Tablenum < 1 Or Tablenum > 9 then 
MsgBox "Not valid!"
Exit Sub
End if
ActiveSheet.PivotTables("PivotTable6").PivotFields  ("DIV").CurrentPage = Tablenum
Ok the validation line is helpful. I will just add a dummy 6 into the table so it will always return a result for 1-9. Ill let you know how it works.
Reply With Quote
  #8  
Old 03-22-2012, 02:34 PM
excelledsoftware excelledsoftware is offline Message Box Restriction Windows 7 64bit Message Box Restriction Office 2003
IT Specialist
Message Box Restriction
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

Quote:
Originally Posted by excelledsoftware View Post
Ok the validation line is helpful. I will just add a dummy 6 into the table so it will always return a result for 1-9. Ill let you know how it works.
Yeah this will work. Its not the perfect solution since I really wanted a list as the validation but 1-9 works too.

Thanks
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Message Box ibrahimaa Excel Programming 3 02-26-2012 02:32 PM
Message Box Restriction navigation arrows post form restriction wcohan Word 1 12-29-2011 11:58 AM
Business Contact Manager "assigned to" restriction rule? kossae Outlook 0 05-25-2011 10:54 AM
Error message White House Outlook 1 12-07-2010 04:52 AM
Outlook Restriction? php link suffix MWE Outlook 0 11-17-2010 07:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft