Does anyone know how to autofill when deleting cells?

BungleNZ

Board Regular
Joined
Sep 9, 2008
Messages
220
Sorry for the repeated post, I thought the title was a little ambiguous and didn't know how to edit it.

Hi, I've got a vba code that automatically fills formulae down a range of cells when a row is inserted. This is all working well, but I would just like to add the same sort of function for when the row is deleted as well.

Can anyone help?

[face=Courier New]
Private Sub Worksheet_Calculate()
Dim lr As Long
ActiveSheet.Unprotect Password:="Bungle" ' Unprotect sheet to allow vba code to run
Application.ScreenUpdating = False
Application.EnableEvents = False
lr = Range("Q1").Value ' This is a reference cell for determing the range to autofill
If lr > Range("Q2").Value Then
Range("K7:M" & lr).FillDown ' Fills down formulae from K7, L7 and M7
Range("K7:M" & lr).Locked = False ' This is to unlock the cells in the range so user can edit them
End If
Range("Q2").Value = lr
Application.EnableEvents = True
Application.ScreenUpdating = True
ActiveSheet.protect Password:="Bungle", _
DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True ' Re-protect sheet and allow deleting and inserting of cells
End Sub
[/face]
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,372
Messages
6,124,532
Members
449,169
Latest member
mm424

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