Consulting

Results 1 to 5 of 5

Thread: Solved: If Or Statement

  1. #1

    Solved: If Or Statement

    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

    [VBA]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[/VBA]

  2. #2
    VBAX Regular
    Joined
    Sep 2011
    Posts
    78
    Location
    Have you tried "And" in stead of "Or"?

  3. #3
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Another way to look at it


    [VBA]

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

    [/VBA]

    Paul

  5. #5
    Thanks Paul that makes sense

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •