Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default test for "A" or "D"

Using XL2000, I'm trying to validate an InputBox entry:

Col = UCase(InputBox("Column for New Member? A or D", "COLUMN", "A"))
If Col = "" Then Exit Sub

This gives a strong enough hint to the novice user, but I want to make it
foolproof and test for "A" OR "D"

How?

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default test for "A" or "D"

David,

Try something like

Dim S As String
S = InputBox("Enter A or D")
Select Case UCase(S)
Case "A", "D"
MsgBox "entry OK"
Case Else
MsgBox "entry invalid"
End Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"David Turner" wrote in message
...
Using XL2000, I'm trying to validate an InputBox entry:

Col = UCase(InputBox("Column for New Member? A or D", "COLUMN",

"A"))
If Col = "" Then Exit Sub

This gives a strong enough hint to the novice user, but I want

to make it
foolproof and test for "A" OR "D"

How?

--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default test for "A" or "D"

David,

Try, then, something like

If S = "A" Or S = "D" Then
' valid entry
Else
' invalid entry
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"David Turner" wrote in message
...
Chip Pearson wrote

Dim S As String
S = InputBox("Enter A or D")
Select Case UCase(S)
Case "A", "D"
MsgBox "entry OK"
Case Else
MsgBox "entry invalid"
End Select


I was hoping for an IF..OR solution as this would really split

my code.

But if noone else chimes in..., Thanks.

--
David



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default test for "A" or "D"

Chip Pearson wrote

Try, then, something like

If S = "A" Or S = "D" Then
' valid entry
Else
' invalid entry
End If


This works:
If Not Col = "A" And Not Col = "D" Then
MsgBox "Invalid entry", vbOKOnly: Exit Sub
End If

--
David
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default test for "A" or "D"

I don't understand what you mean by "split my code". How does the Select Case block differ from
an If/End if block in this situation?

BTW, you could also write that as

If Not (S = "A" or S = "D") Then

or

If Len(S) < 1 Or Instr("AD",S) = 0 Then


On Sat, 09 Aug 2003 17:41:52 -0700, David Turner wrote:

Chip Pearson wrote

Dim S As String
S = InputBox("Enter A or D")
Select Case UCase(S)
Case "A", "D"
MsgBox "entry OK"
Case Else
MsgBox "entry invalid"
End Select


I was hoping for an IF..OR solution as this would really split my code.

But if noone else chimes in..., Thanks.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default test for "A" or "D"

Myrna Larson wrote

I don't understand what you mean by "split my code". How does the
Select Case block differ from an If/End if block in this situation?


All code following a valid Column entry would take the place of Chip's
MsgBox "entry OK" and the Case Else would follow that. Not True?

If Not (S = "A" or S = "D") Then


I like it.

Thanks for jumping in.

--
David
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default test for "A" or "D"

I don't understand the explanation, but I think by splitting the
code David meant that he can see more of the other code
on the screen with less scrolling when fewer lines are used
for the test. Why else would one want to test for a negative
(NOT) conditions when positives are generally easier to read
and less confusing..
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"David Turner" wrote in message ...
Myrna Larson wrote

I don't understand what you mean by "split my code". How does the
Select Case block differ from an If/End if block in this situation?


All code following a valid Column entry would take the place of Chip's
MsgBox "entry OK" and the Case Else would follow that. Not True?

If Not (S = "A" or S = "D") Then


I like it.

Thanks for jumping in.

--
David



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default test for "A" or "D"

I am not sure, but if one enters an invalid character by accident, would you
want them to try again, or exit the Sub by default? As an general idea,
perhaps you could loop until they enter a valid character. Again, just an
thought.

Sub Demo()
Dim S As String
Dim Ok As Boolean
Ok = False

Do
S = UCase(InputBox("Enter A or D (Blank to exit)"))
Select Case S
Case "A", "D"
Ok = True
MsgBox "entry OK"
Case vbNullString
Ok = True
MsgBox "Blank...about to exit sub"
Case Else
Ok = False
MsgBox "Innvalid: Enter A, D, or Blank to exit"
End Select
Loop While Not Ok

If S = vbNullString Then Exit Sub

' Continue with code. S = A or D
'....
End Sub


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"David Turner" wrote in message
...
Myrna Larson wrote

I don't understand what you mean by "split my code". How does the
Select Case block differ from an If/End if block in this situation?


All code following a valid Column entry would take the place of Chip's
MsgBox "entry OK" and the Case Else would follow that. Not True?

If Not (S = "A" or S = "D") Then


I like it.

Thanks for jumping in.

--
David



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default test for "A" or "D"

Dana DeLouis wrote

I am not sure, but if one enters an invalid character by accident,
would you want them to try again, or exit the Sub by default? As an
general idea, perhaps you could loop until they enter a valid
character. Again, just an thought.


Yes, I've opted to exit by default. The most common user error that occurs
is that they start typing a name to Add or Remove from one of the columns
since that is the prompt that follows the column choice.

Interesting idea to loop until valid entry is made, though. I'm just too
fanatical about keeping number of lines of code in a module to a minimum.

--
David
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default test for "A" or "D"

If you object to the Not, you have a couple of other options:

If S = "A" or S = "D" Then
'leave empty or put there the code that would
'ordinarily follow the End If
Else
'error message
Exit Sub
End If

If S < "A" and S < "D" Then



On Sun, 10 Aug 2003 09:45:24 -0400, "David McRitchie" wrote:

I don't understand the explanation, but I think by splitting the
code David meant that he can see more of the other code
on the screen with less scrolling when fewer lines are used
for the test. Why else would one want to test for a negative
(NOT) conditions when positives are generally easier to read
and less confusing..
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"David Turner" wrote in message

...
Myrna Larson wrote

I don't understand what you mean by "split my code". How does the
Select Case block differ from an If/End if block in this situation?


All code following a valid Column entry would take the place of Chip's
MsgBox "entry OK" and the Case Else would follow that. Not True?

If Not (S = "A" or S = "D") Then


I like it.

Thanks for jumping in.

--
David



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM


All times are GMT +1. The time now is 04:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"