VBA If condition

D

Dan E

I want to test for something like this -

If Cells (oRow.Row, "AT").Value = "1" OR "2" OR "3" Then
Cells(oRow.Row, "BA").Value = 0
ElseIf....

buy am unclear how to express the OR conditions in VBA.

All help gratefully received and acknowledged!

TIA,

Dan
 
C

Chip Pearson

Try something like

If Cells(oRow.Row,"AT").Value = "1" Or _
Cells(oRow.Row,"AT").Value = "2" Or _
Cells(oRow.Row,"AT").Value= "3" Then
Cells(oRow.Row,"BA").Value = 0
.....


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

Dan E

Many thanks, Chip!

Dan
Chip Pearson said:
Try something like

If Cells(oRow.Row,"AT").Value = "1" Or _
Cells(oRow.Row,"AT").Value = "2" Or _
Cells(oRow.Row,"AT").Value= "3" Then
Cells(oRow.Row,"BA").Value = 0
....


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

Dave Peterson

You may want to look at VBA's help for "select case"

select case cells(orow.row,"AT").value
case is = 1, 2, 3
cells(orow.row,"BA").value = 0
end select

(Did you really want text 1, 2, 3 ("1", "2", "3")?)
 
D

Dan E

Hi Dave - no, I didn't want "1" - I forgot I didn't need the quotes for
numbers - slow learner! Thanks for the case syntax; would this also work?:-

If Cells (oRow.Row, "AT").Value = 1, 2, 3 Then
Cells(oRow.Row, "BA").Value = 0
' or "" instead of 0 - I actually want to make a blank cell
ElseIf....

TIA,

Dan
 
D

Dave Peterson

Nope.

You'd have to use syntax like Chip suggested or the "select case" stuff.

And to blank out that cell:
cells(orow.row,"BA").value = ""
or even
cells(orow.row,"BA").clearcontents


Dan said:
Hi Dave - no, I didn't want "1" - I forgot I didn't need the quotes for
numbers - slow learner! Thanks for the case syntax; would this also work?:-

If Cells (oRow.Row, "AT").Value = 1, 2, 3 Then
Cells(oRow.Row, "BA").Value = 0
' or "" instead of 0 - I actually want to make a blank cell
ElseIf....

TIA,

Dan
 
D

Dan E

Many thanks Dave.

Dan
Dave Peterson said:
Nope.

You'd have to use syntax like Chip suggested or the "select case" stuff.

And to blank out that cell:
cells(orow.row,"BA").value = ""
or even
cells(orow.row,"BA").clearcontents
 
Top