![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 9
|
Is there code that will validate a responce from an Input Box and display a message if the response is incorrect?
Please see the Macro below. It works great if I enter the correct data field in the input box, but if I enter incorrect data, the Macro fails. I have experimented with an If-Then-Elself code but I dont know where to put it. It will not work correctly. Sub SortData3() ' ' SortData3 Macro ' Macro recorded 4/28/2002 by Jerry Russell ' ' Range("A8:G27").Select Selection.Sort Key1:=InputBox("Type Tours, Start, Stop, Type, Sold, Open, Price"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Range("A1").Select End Sub |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Hi JRussel,
An example, modify as needed: If [A18] > 1 Then MsgBox "you can only enter the value 1 A18", _ vbOkOnly + vbExcalmation End If End Sub James |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Hi,
Will this work for you? '------ Sub SortData3() Dim x As String, y As Integer, MyArr MyArr = Array("tours", "start", "stop", "type", "sold", "open", "price") x = LCase(Application.InputBox("Type in one of the following to sort:" _ & vbCr & "Tours, Start, Stop, Type, Sold, Open, Price")) On Error Resume Next y = Application.Match(x, MyArr, 0) On Error GoTo 0 If y = 0 Then MsgBox "Invalid Entry" Exit Sub End If With Range("A8").CurrentRegion .Sort Key1:=.Cells(8, y), Order1:=xlAscending, Header:=xlYes End With End Sub '------ |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|