Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default vba using the OR operator

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default vba using the OR operator

You need to do:

If Rows(iRow, 1) = "11/13/2005" Or Rows(iRow, 1) = "11/23/2005" Then


RBS


"Mona" wrote in message
...
Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default vba using the OR operator

Monda,

Try it this way:

If Rows(iRow,1).value = #11/13/2005# or Rows(iRow,1).value = #11/23/2005" Then
'* YOUR CODE HERE *
End if


"Mona" wrote:

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default vba using the OR operator

Thank you Vergel for reply but I am getting error on this code:

If Rows(iRow, 1).Value = "11/13/2005" Or Rows(iRow, 1).Value = "11/23/2005"
Then

**code**
end if

"Vergel Adriano" wrote:

Monda,

Try it this way:

If Rows(iRow,1).value = #11/13/2005# or Rows(iRow,1).value = #11/23/2005" Then
'* YOUR CODE HERE *
End if


"Mona" wrote:

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default vba using the OR operator

Firstly, Rows(iRow,1) won't work. Do you mean Cells(iRow,1)?

You could put all the dates in an array and then loop the array, e.g.

Dim bFlag As Boolean
myArray = Array(#11/15/2005#, #11/23/2005#)
For iCt = 0 To UBound(myArray)
If Cells(iRow, 1) = myArray(iCt) Then
bFlag = True
Exit For
End If
Next iCt
If bFlag = True Then
'do something
End If

Hth,
Merjet




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default vba using the OR operator

Should it not be:

If Cells(iRow, 1).Value

RBS


"Mona" wrote in message
...
Thank you Vergel for reply but I am getting error on this code:

If Rows(iRow, 1).Value = "11/13/2005" Or Rows(iRow, 1).Value =
"11/23/2005"
Then

**code**
end if

"Vergel Adriano" wrote:

Monda,

Try it this way:

If Rows(iRow,1).value = #11/13/2005# or Rows(iRow,1).value = #11/23/2005"
Then
'* YOUR CODE HERE *
End if


"Mona" wrote:

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get
by
with just repeating the code 20 times but I wanted to do it using a
single
statement.

Thank you!!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default vba using the OR operator

Try using the Cells collection instead of Rows. So, use

Cells(iRow, 1)

instead of

Rows(iRow, 1)





"Mona" wrote:

Thank you Vergel for reply but I am getting error on this code:

If Rows(iRow, 1).Value = "11/13/2005" Or Rows(iRow, 1).Value = "11/23/2005"
Then

**code**
end if

"Vergel Adriano" wrote:

Monda,

Try it this way:

If Rows(iRow,1).value = #11/13/2005# or Rows(iRow,1).value = #11/23/2005" Then
'* YOUR CODE HERE *
End if


"Mona" wrote:

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default vba using the OR operator

sub ifcells()
If cells(iRow, 1) ="11/13/2005" Or cells(irow.1)="11/23/2005") Then msgbox
"ok"
end sub

--
Don Guillett
SalesAid Software

"Mona" wrote in message
...
Here is my code that does not work:

I can get the code to work on a single date but not with multiple dates

using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!



  #9   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default vba using the OR operator

The Rows property does not take multiple arguments. If you want to search
all cells in each entire row, try the following:

If Not Range(Rows(1), Rows(iRow)).Find(DateValue("11/13/2005")) Is Nothing
Or _
Not Range(Rows(1), Rows(iRow)).Find(DateValue("11/23/2005")) Is Nothing Then

....Your code Here....

End If

Note also that the example above assumes you are searching for actual dates.
Your original example shows a search for a strings "11/13/2005" and
"11/23/2005." If you really want to search for the string, delete the
DateValue characters from the example.
--
Jay


"Mona" wrote:

Here is my code that does not work:

If Rows(iRow, 1) = ("11/13/2005" Or "11/23/2005") Then
blah blah

I can get the code to work on a single date but not with multiple dates
using "or". I have about 20 dates that I want to check and I could get by
with just repeating the code 20 times but I wanted to do it using a single
statement.

Thank you!!

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
Operator for Contains Leanne M (Aussie) Excel Worksheet Functions 2 October 21st 08 11:01 AM
XOR Operator - How? Randy Brown Excel Discussion (Misc queries) 3 April 8th 06 09:47 PM
Mod operator R Avery Excel Programming 7 September 2nd 04 03:03 AM
Like Operator Donald[_3_] Excel Programming 8 June 29th 04 03:22 AM
Can the AND operator be of use here? Milind Excel Programming 3 July 27th 03 11:17 PM


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