Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Excel VBA OR statement

Why does the OrRstatement for "y" does not work?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Column = 3 Then

If (Target.Text = "Y" Or "y") Then

Target.Offset(0, 1).FormulaR1C1 = Now()
Target.Offset(0, 2).Interior.ColorIndex = 5
Target.Offset(0, 3).Interior.ColorIndex = 4

End If
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Excel VBA OR statement

Mybe you should use:
If (Target.Text = "Y" Or Target.Text = "y") Then

OR:

If (ucase(Target.Text) = "Y") Then

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Excel VBA OR statement

If Target.Text = "Y" Or Target.Text = "y" Then

Gordon Rainsford
--

wrote:

Why does the OrRstatement for "y" does not work?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Column = 3 Then

If (Target.Text = "Y" Or "y") Then

Target.Offset(0, 1).FormulaR1C1 = Now()
Target.Offset(0, 2).Interior.ColorIndex = 5
Target.Offset(0, 3).Interior.ColorIndex = 4

End If
End If

End Sub



--
Gordon Rainsford

London UK
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Excel VBA OR statement

The syntax is wrong. Use something like

If (Target.Text = "Y") Or (Target.Text = "y") Then

Or, to simplify and get rid of the Or altogether, you could use

If StrComp(target.Text, "y", vbTextCompare) = 0 Then
' equal
Else
' not equal
End If

Additionally, if you put 'Option Compare Text' as the first line
in your code module (outside of and before any procedure or
public variable), all text comparisons will ignore case, so you
could write

If Target.Text = "y" Then



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



wrote in message
oups.com...
Why does the OrRstatement for "y" does not work?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Column = 3 Then

If (Target.Text = "Y" Or "y") Then

Target.Offset(0, 1).FormulaR1C1 = Now()
Target.Offset(0, 2).Interior.ColorIndex = 5
Target.Offset(0, 3).Interior.ColorIndex = 4

End If
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
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM
If..Else Statement in Excel Sheela[_2_] Excel Programming 7 July 21st 03 07:36 AM


All times are GMT +1. The time now is 03:56 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"