if single cell value is found in a range then delete entire row

后端 未结 1 1652
春和景丽
春和景丽 2021-01-24 07:34

I am working with daily data that recorded 31 days of data per multiple stations and I need a VBA code to remove leap year days. I have a list of dates of data recorded and a l

1条回答
  •  被撕碎了的回忆
    2021-01-24 08:35

    Modified version of my answer from This Question

    Sub Sample()
    
    Dim StartingScreenUpdateValue As Boolean
    Dim StartingEventsValue As Boolean
    Dim StartingCalculations As XlCalculation
    
    With Application
        StartingScreenUpdateValue = .ScreenUpdating
        StartingEventsValue = .EnableEvents
        StartingCalculations = .Calculation
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    
    
    Dim varTestValues As Variant
    
    varTestValues = Workbooks("LeapYears.xlsx").Sheets(1).Range("C2:C90")
    
    Rows(1).Insert
    [A1].FormulaR1C1 = "TempHeader1"
    [A1].AutoFill Destination:=Range("A1:H1"), Type:=xlFillDefault
    
    Range("D1").AutoFilter Field:=4, Criteria1:=Application.Transpose(varTestValues), Operator:=xlFilterValues
    
    Range("D2", Range("D" & Rows.Count).End(xlUp)) _
        .SpecialCells(xlCellTypeVisible).EntireRow.Delete
    
    ActiveSheet.AutoFilterMode = False
    Rows(1).Delete
    
    
    With Application
        .ScreenUpdating = StartingScreenUpdateValue
        .EnableEvents = StartingEventsValue
        .Calculation = StartingCalculations
    End With
    
    End Sub
    

    NOTE: This code runs assuming your data has headers if it does not please advise.

    REMEMBER Always run any code on a copy of your data and not your actual data until you are confident that it is working 100%.

    0 讨论(0)
提交回复
热议问题