![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 107
|
Is there a macro that can run if it detects that a user deletes one or more entire rows? Something like the following:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) If any entire row is deleted then End If End Sub |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi Pinball.
As you maybe know, excel does not have such an event. So, I thought anothe way using calculate event. Pls, try this and hope this help. Before you try this you need to de-active activesheet, and re-active the sheet. (May be you will not be able to understand what I want to say, because of my bad English...)
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Posts: 107
|
Colo, Thanks for your response.
What are your thoughts towards my beginner's code below to accomplish my goal? It seems to work..the only tiny disadvantage is that after deleting row(s) the user has to click on any cell for the macro to run (but I can certainly live with that!). Question: Is it possible to revise this code so that I do not need to store the p value in a cell, but store it in memory instead? Thanks. Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Dim p As Integer p = ActiveSheet.UsedRange.Rows.Count If p < Range("D1").Value Then 'Following line is a test formula Range("a1").Formula = 1 + p End If Range("D1").Formula = p End Sub |
|
|
|
|
|
#4 |
|
Join Date: Feb 2002
Posts: 47
|
Alternatively, you could store it in a separate hidden worksheet.
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi again.
-- quote----------------------------- but store it in memory instead? ------------------------------------- I guess, if you use public Variable. But the best way is store it in a separate hidden worksheet as Tikas wrote. By the way, if your version of xl is XL2000, try another way I thought. Please paste this into sheet module.
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi Pinball, Are you still watching here?
Here is another way.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|