DateAdd to Filtered Data

GreatOffender

Board Regular
Joined
Feb 2, 2015
Messages
53
Trying to make this simple and easy to understand. I have spreadsheet with transaction types in the “C” column. There are due dates in the “L” column. I need to filter the “C” column by certain values and increase the dates in the “L” column by one day. My problem is that I seem to get turned around after I filter the column and my DateAdd increase everything and not just the filtered values. I am trying to avoid creating the dummy sheet example but will add it if necessary. My confusion starts after the filtering

VBA Code:
Sub Date_Add()
    Dim rngData As Range
    Dim ws As Worksheet
    Dim lngLastRow As Long
    Set ws = Sheets(1)
   
    With ws
        .Columns("A:Q").AutoFilter
        lngLastRow = .Range("C" & .Rows.Count).End(xlUp).Row
        Set rngData = .Range("C2:C" & lngLastRow)
    End With
   
    Application.DisplayAlerts = False
    With rngData
        .AutoFilter Field:=3, Criteria1:=Array( _
            "3456", "3125", "3451", "3110", "3370"), Operator:=xlFilterValues
        ?????????
   
    Application.DisplayAlerts = True
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

VBA Code:
Sub Date_Add()
  Dim rngData As Range, c As Range
  Dim ws As Worksheet
  Dim lngLastRow As Long
  
  Set ws = Sheets(1)
  With ws
    If .AutoFilterMode Then .AutoFilterMode = False
    .Columns("A:Q").AutoFilter
    lngLastRow = .Range("C" & .Rows.Count).End(xlUp).Row
    Set rngData = .Range("C2:C" & lngLastRow)
  End With
  
  Application.DisplayAlerts = False
  With rngData
    .AutoFilter Field:=3, Criteria1:=Array( _
        "3456", "3125", "3451", "3110", "3370"), Operator:=xlFilterValues
    For Each c In ws.AutoFilter.Range.Range("L2:L" & lngLastRow).SpecialCells(xlCellTypeVisible)
      c.Value = c.Value + 1
    Next
  End With
  Application.DisplayAlerts = True
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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