DateAdd Function Question

rodrigo_m_almeida

New Member
Joined
Jan 13, 2022
Messages
42
Office Version
  1. 2021
Platform
  1. Windows
Good Morning,

I need to subtract 1 day for date that time is less than 02:59:59

VBA Code:
Public Sub BradPitt()
    With ActiveSheet
            .AutoFilterMode = False
                With Range("D1", Range("D" & Rows.Count).End(xlUp))
                    .AutoFilter 1, "<02:59:59"
                    On Error Resume Next
                    .Columns(-2).Offset(1).SpecialCells(12).Value = DateAdd("d", -1, ActiveCell) ' PROBLEM <
                End With
            .AutoFilterMode = False
        End With
End Sub

Using "ActiveCell" in DateAdd, no subtract anything from the found cell

I'm trying to do this with autofilter because my sheet is too big...
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
VBA Code:
Public Sub BradPitt()
     With ActiveSheet
          Set c1 = .Range("AA1")                                'somewhere an auxiliary cell
          c1.Value = -1                                         'value you want to substract

          .AutoFilterMode = False
          With Range("D1", Range("D" & Rows.Count).End(xlUp))
               Set c = .Offset(1, -2).Resize(.Rows.Count - 1)   'Column B without the header
               .AutoFilter 1, "<02:59:59"
               If .SpecialCells(12).Count > 1 Then
                    c1.Copy                                     'that -1
                    c.SpecialCells(12).PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd, SkipBlanks:=False, Transpose:=False     'substract if from previous value for all visible cells
               End If
          End With
          .AutoFilterMode = False
     End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top