View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
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