Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IF Function (Excel 2003)

    I hope someone can help me with this excel IF statement.

    I have an excel sheet that has temperature readings entered automatically every 10 minutes. I would like the entire row to be entered if the temperature is different from the row above. If the temperature is the same, delete or leave out the entire row . The spreadsheet has 4 columns entering time, date, depth and temperature. i.e. enter data only if the temperature changes, otherwise delete the entire row.

    Thank you...Susan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: IF Function (Excel 2003)

    I don't think you can do this using formulas, you'd need to use VBA code. But if the temperature readings are entered automatically, when should the code run?

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: IF Function (Excel 2003)

    Try placing this in the Worksheet code <pre>Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 4 Then 'Assumes Temperature is in coliumn 4 (D)
    Application.OnTime Now + TimeValue("00:00:05"), "Compare_Temps"
    End If
    End Sub</pre>



    And this in a standard module <pre>Option Explicit
    Public Sub Compare_Temps()
    Dim ROI As Long

    ' Set COI to the Temperature column
    Const COI = 4

    Application.EnableEvents = False
    ROI = Range(Cells(65536, COI).Address).End(xlUp).Row
    If Cells(ROI, COI) = Cells(ROI - 1, COI) Then
    Range("A" & ROI).EntireRow.Delete
    End If
    Application.EnableEvents = True
    End Sub</pre>




    The delay has been set to 5 seconds to allow the data entry to be completed irrespective of the entry order.

    HTH
    Regards
    Don

Posting Permissions

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