Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Fix If statment to accept Upper or Lower Case

Macro will not work if input box entry is in upper case and If statment = a item in lower cas
Is there a way to fix so macro will work regardless of how entered in input bo
Thank
Bob Leonar

Sub TestIf(

Dim varInput As Strin
Range("P5").Selec
varInput = InputBox("Enter Value"
Selection.VALUE = varInpu

If Selection.VALUE = "test_1" The
Application.Run "test

ElseIf Selection.VALUE = "test_2" Then
Application.Run "test2

End I
End Su

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Fix If statment to accept Upper or Lower Case

Bob,

At the very top of the code module, above and outside of any
procedures, put the line

Option Compare Text


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



"rleonard" wrote in message
...
Macro will not work if input box entry is in upper case and If

statment = a item in lower case
Is there a way to fix so macro will work regardless of how

entered in input box
Thanks
Bob Leonard


Sub TestIf()

Dim varInput As String
Range("P5").Select
varInput = InputBox("Enter Value")
Selection.VALUE = varInput

If Selection.VALUE = "test_1" Then
Application.Run "test"

ElseIf Selection.VALUE = "test_2" Then
Application.Run "test2"

End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Fix If statment to accept Upper or Lower Case

I don't think it's the macro that's causing the error.

if lcase(selection.value) = "test_1" then
should work ok.

or this too:
if lcase(varinput) = "test_1" then


It's the text comparison that's causing the trouble.

If you always want to ignore upper/lower case differences, you can add:

Option Compare Text

at the top of the module.



rleonard wrote:

Macro will not work if input box entry is in upper case and If statment = a item in lower case
Is there a way to fix so macro will work regardless of how entered in input box
Thanks
Bob Leonard

Sub TestIf()

Dim varInput As String
Range("P5").Select
varInput = InputBox("Enter Value")
Selection.VALUE = varInput

If Selection.VALUE = "test_1" Then
Application.Run "test"

ElseIf Selection.VALUE = "test_2" Then
Application.Run "test2"

End If
End Sub


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Fix If statment to accept Upper or Lower Case

Typical solution is to force both sides of the comparison to all upper case
or all lower case.

If LCase(varInput) = LCase("test_1") Then

Troy

"rleonard" wrote in message
...
Macro will not work if input box entry is in upper case and If statment =

a item in lower case
Is there a way to fix so macro will work regardless of how entered in

input box
Thanks
Bob Leonard


Sub TestIf()

Dim varInput As String
Range("P5").Select
varInput = InputBox("Enter Value")
Selection.VALUE = varInput

If Selection.VALUE = "test_1" Then
Application.Run "test"

ElseIf Selection.VALUE = "test_2" Then
Application.Run "test2"

End If
End Sub



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
convert lower to upper case automatically without using UPPER Sal Excel Discussion (Misc queries) 6 July 26th 09 11:27 AM
Changing upper case characters to upper/lower Richard Zignego Excel Discussion (Misc queries) 1 December 17th 07 10:09 PM
Changing file in all upper case to upper and lower case Sagit Excel Discussion (Misc queries) 15 May 30th 07 06:08 AM
Change from mixed caps and upper lower to all upper lower case Fish''s Mermaid Excel Worksheet Functions 3 October 13th 06 02:15 PM
How do I convert all upper case excel sheet into upper and lower . DebDay Excel Discussion (Misc queries) 1 March 9th 05 08:31 PM


All times are GMT +1. The time now is 06:34 PM.

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

About Us

"It's about Microsoft Excel"