and, or in vbe

  • Thread starter Thread starter N+
  • Start date Start date
N

N+

hi all !! how can i do the AND , OR function of worksheet
in the vbe ??
ty for helping !!
paolo
 
In VB, And and Or are not functions, they are operators... you would use
them in much the same way as you would use plus, minus, multiply, etc. For
example...

If (A > 4) And (B <= 10) Then

Rick
 
Hi Paolo,

Perhaps the following procedure will
be of assistance:

'===========>>
Public Sub Tester()
Dim Rng As Range
Dim rng2 As Range

With ActiveSheet
Set Rng = .Range("A1")
Set rng2 = .Range("A2")
End With

Rng.Value = 10
rng2 = 20

If Rng >= 10 _
And rng2 >= 10 Then
MsgBox Prompt:="Both >= 9"
End If

If Rng >= 10 _
Or rng2 >= 10 Then
MsgBox Prompt:="At least one value >= 10"
End If

End Sub
'<<===========
 
I'm not sure what you're asking. VBA has its own 'And' and 'Or' comparison
operators. If you want to use the worksheet function, you can do something
like

Application.WorksheetFunction.Or

If you want to create a formula in a cell, try something like

Dim F As String
F = "=OR(A1,B1)"
Range("C1").Formula = F


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
AND and OR are operators in VBA, not functions in the worksheet:

Sub and_or()
If Range("A1").Value = 1 And Range("A2").Value = 1 Then
MsgBox ("Both are one")
End If

If Range("A1").Value = 1 Or Range("A2").Value = 1 Then
MsgBox ("At least one is one")
End If

End Sub
 
'''''''''''DONE TY !!'''''''''''''''

Gary''s Student said:
AND and OR are operators in VBA, not functions in the worksheet:

Sub and_or()
If Range("A1").Value = 1 And Range("A2").Value = 1 Then
MsgBox ("Both are one")
End If

If Range("A1").Value = 1 Or Range("A2").Value = 1 Then
MsgBox ("At least one is one")
End If

End Sub
 
Set rng = Selection
For Each cell In rng
If cell.Text = "0" Or cell.Text = "" And _
cell.Offset(0, 3).Value = "hoohah" Then
cell.EntireRow.Interior.ColorIndex = 6
End If
Next


Gord Dibben MS Excel MVP
 
Back
Top