PDA

View Full Version : Solved: If Or Statement



dodonohoe
04-24-2013, 04:17 AM
Hi Guys,

I've been trying to get what Im sure is a simple If Or statement working. If I just have the If statement there it works fine but once I add the "or" the macro deletes everything

Sub removeextra()
Dim ws As Worksheet
Set ws = Worksheets("Geneva_Workings")
Dim MyVal As String
Dim Receivable As String
Dim Payable As String
Sheets("Geneva_Workings").Select
rowno = 2
Do Until Cells(rowno, 1) = ""
MyVal = Cells(rowno, 8)
Receivable = "Receivables for Securities Sold"
Payable = "Payables for Securities Purchased"
If MyVal <> Receivable Or MyVal <> Payable Then
ws.Cells(rowno, 1).EntireRow.Delete
rowno = rowno - 1
End If
rowno = rowno + 1
Loop
End Sub

zagrijs
04-24-2013, 04:38 AM
Have you tried "And" in stead of "Or"?

dodonohoe
04-24-2013, 05:48 AM
Thank you very much, that worked perfectly zagrijs but I am unsure as to why. I will muddle it over in my head until it makes sense but thanks again.

Des

Paul_Hossler
04-24-2013, 11:19 AM
Another way to look at it




If Not (MyVal = Receivable And MyVal = Payable) Then
.....



Paul

dodonohoe
04-24-2013, 11:52 AM
Thanks Paul that makes sense