+ Reply to Thread
Results 1 to 3 of 3

How do I write If then statements?

Hybrid View

  1. #1
    If...Then Statement
    Guest

    How do I write If then statements?

    I have imported data from APO into excel. There are at least 40 rows. How
    do I write an If statement.
    If A1 = A2 through A40 and B1=b2 through b40 and c1=c2 through c40 then keep
    row that has the earliest requested date.

    For Example
    Product PO# Requested Date Delivery Date
    A123 234 Jan 20, 2006 June 1, 2006
    A123 234 Mar 2, 2006 June 1, 2006
    A123 234 April 2,2006 Jume 1, 2006

    I am thinking a macro can delete the later requeted adtes if the rows are =?

    Thanks,
    Terry

  2. #2
    Norman Jones
    Guest

    Re: How do I write If then statements?

    Hi Terry,

    Try :
    '=============>>
    Public Sub Tester4()
    Dim WB As Workbook
    Dim SH As Worksheet
    Dim rng As Range
    Dim i As Long
    Dim LRow As Long

    Set WB = Workbooks("Your Workbook.xls") '<<==== CHANGE
    Set SH = WB.Sheets("Sheet3") '<<==== CHANGE

    LRow = SH.Cells(Rows.Count, "A").End(xlUp).Row

    For i = LRow To 3 Step -1
    Set rng = SH.Cells(i, "A")
    If rng.Value = rng(0).Value _
    And rng(1, 2).Value = rng(0, 2).Value Then
    If rng(1, 3).Value > rng(0, 3).Value Then
    rng.EntireRow.Delete
    Else
    rng(0).EntireRow.Delete
    End If
    End If
    Next i

    End Sub
    '<<=============


    ---
    Regards,
    Norman


    "If...Then Statement" <If...Then Statement@discussions.microsoft.com> wrote
    in message news:3943D674-E431-4BD3-B601-0165B3A88182@microsoft.com...
    >I have imported data from APO into excel. There are at least 40 rows. How
    > do I write an If statement.
    > If A1 = A2 through A40 and B1=b2 through b40 and c1=c2 through c40 then
    > keep
    > row that has the earliest requested date.
    >
    > For Example
    > Product PO# Requested Date Delivery Date
    > A123 234 Jan 20, 2006 June 1, 2006
    > A123 234 Mar 2, 2006 June 1, 2006
    > A123 234 April 2,2006 Jume 1, 2006
    >
    > I am thinking a macro can delete the later requeted adtes if the rows are
    > =?
    >
    > Thanks,
    > Terry




  3. #3
    Norman Jones
    Guest

    Re: How do I write If then statements?

    Hi Terry,

    I should add that the suggested code assumes that the entries in the
    Requested Date Column are recognised as dates by Excel.


    ---
    Regards,
    Norman



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1