Keep only 12 rows of data in an excel table

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
223
Office Version
  1. 365
Platform
  1. Windows
In order to calculate holiday entitlement, I am hoping that I can create either a table or database which only contains 12 lines of information. As each new line of data is added, I am hoping to automatically remove the information in the first row of data

Table Format
Row 1 - Row Headers
Row 2 - Week 1 Data
Row 3 - Week 2 Data
.....
Row 13 - Week 12 Data

Once data is entered into Row 14 , I would like to run a macro which would delete the information in Row 2 making Row 3 into Row 2. This would continue until Row 14 becomes Row 13

I will then be able to run formulae to extract the information I need to maintain the records I need to extract

This may not be the most effective solution as staff will be added and changed periodically, but will help until I can create a better solution

All help will be most welcome
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Denny let's get the ball rolling. Below is my solution to your problem. Now this usually generates more questions than answers but we have to start somewhere. If we are lucky an A student will weigh in and will do the same thing with 2 lines of code. Let's start the discussion.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim InterSectRange As Range

Set WatchRange = Range("B15")

Set InterSectRange = Intersect(Target, WatchRange)
If InterSectRange Is Nothing Then

Else

Application.EnableEvents = False
Rows("2:2").Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
Application.EnableEvents = True
End If

End Sub

24-01-20 rev a.xlsm
AB
1WeekData
2Week 1Data 1
3Week 2Data 2
4Week 3Data 3
5Week 4Data 4
6Week 5Data 5
7Week 6Data 6
8Week 7Data 7
9Week 8Data 8
10Week 9Data 9
11Week 10Data 10
12Week 11Data 11
13Week 12Data 12
14Week 13Data 13
Sheet1
 
Upvote 0
I can create either a table
Would that be a formal Excel table (ListObject) created for example through the Insert ribbon tab -> Table or just a range of cells that you are referring to as a table?

If it is a formal Excel table then you could consider the suggestion in this post, changing the "52" in that code to "12"
That suggestion doesn't require you to "run" anything as such. As soon as there are more than 12 rows in the table rows will automatically be deleted from the top until just 12 remain.
 
Last edited:
Upvote 0
Solution
Would that be a formal Excel table (ListObject) created for example through the Insert ribbon tab -> Table or just a range of cells that you are referring to as a table?

If it is a formal Excel table then you could consider the suggestion in this post, changing the "52" in that code to "12"
That suggestion doesn't require you to "run" anything as such. As soon as there are more than 12 rows in the table rows will automatically be deleted from the top until just 12 remain.
Thanks, works fine
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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