Clear Contents two cells to the left if input date is <

ExcelArtist2019

New Member
Joined
Nov 29, 2019
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Attempting to modify a MACRO that deletes rows based on input box date < criteria - that works great! Now need to just clear contents of cell two cells to the left and not an entire row. Not sure what needs to be done on this line: ActiveCell.Offset(0, -2).ClearContents - not working. Dates and row counts continually change/increase. Including screen shot of sample data.


Sub FifthSCCMacro()
'
' FifthSCCMacro Macro
' Clear cell contents Add-on CLINs two cells to the left (Column J) based on all end dates older then date entered in input box on column L data
'
Dim LastRow As Long, x As Long
Dim resp
resp = InputBox("Enter value to clear", "ClearContents")
If resp = "" Then Exit Sub
MsgBox ("Are you sure you want to clear add-ons " & resp)
LastRow = Cells(Cells.Rows.Count, "L").End(xlUp).Row
If IsDate(resp) Then
resp = CDate(resp)
End If
For x = LastRow To 1 Step -1
If IsDate(resp) Then
If Cells(x, "L").Value < resp Then
ActiveCell.Offset(0, -2).ClearContents
End If
End If

If Not IsDate(resp) Then
If UCase(Cells(x, "L").Value) < UCase(resp) Then
ActiveCell.Offset(0, -2).ClearContents
End If
End If
Next
End Sub
 

Attachments

  • SampleData.JPG
    SampleData.JPG
    30.6 KB · Views: 10

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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