auto delete data at the start of every month

adityatandel

Board Regular
Joined
Aug 10, 2007
Messages
71
Hi,

I have a column with data which is connected to dates in another column. the numbers column gets filled as the days progress in the month. how do i get this column to recognize the start of a new month and delete the data of the previous month?

Thanks,
Adi
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Hello adityatandel,
Assuming:
(1) The worksheet in question is named Sheet1
(2) The column to get cleared is column B
(3) You have headers in row 1 of Sheet1
(4) Your users will always have their security setting to allow either (automatically or manually)
macros to be enabled. . .

You can try this in your ThisWorkbook module.
Code:
Private Sub Workbook_Open()
If Day(Now) = 1 Then
  Dim LstRw As Long
  LstRw = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row
  If LstRw >= 3 Then
    Sheets("Sheet1").Range("B2:B" & LstRw).ClearContents
  End If
End If
End Sub

Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,191,686
Messages
5,988,073
Members
440,125
Latest member
vincentchu2369

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
Top