How do I write If then statements?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
'<<=============
 
Hi Terry,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top