MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2002, 10:36 PM   #1
Pinball
Board Regular
 
Join Date: Apr 2002
Posts: 107
Default

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
Pinball is offline   Reply With Quote
Old May 1st, 2002, 12:50 AM   #2
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

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...)


Private Sub Worksheet_Activate()
Cells(Rows.Count, Columns.Count).Formula = "=A1"
End Sub

Private Sub Worksheet_Calculate()
Dim strMsg As String
If IsEmpty(Cells(Rows.Count, Columns.Count)) Then
Application.ScreenUpdating = False
Rows(Rows.Count).Clear
Columns(Columns.Count).Clear
Cells(Rows.Count, Columns.Count).Formula = "=A1"
With Selection
If .Columns.Count = Columns.Count Then strMsg = "Rows "
If .Rows.Count = Rows.Count Then strMsg = "Columns "
End With
Application.ScreenUpdating = True
Call ShowMsgBox(strMsg)
End If
End Sub

Private Sub ShowMsgBox(str)
MsgBox str & "were deleted"
End Sub



__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Old May 1st, 2002, 03:38 AM   #3
Pinball
Board Regular
 
Join Date: Apr 2002
Posts: 107
Default

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
Pinball is offline   Reply With Quote
Old May 1st, 2002, 06:58 AM   #4
Tikas A. Planck
 
Join Date: Feb 2002
Posts: 47
Default

Alternatively, you could store it in a separate hidden worksheet.
Tikas A. Planck is offline   Reply With Quote
Old May 1st, 2002, 08:56 AM   #5
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

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.



Dim R_Count As Long
Dim C_Count As Long

Private Sub Worksheet_Change(ByVal Target As Range)
Dim strMsg As String
If UsedRange.Rows.Count < R_Count Then strMsg = "Rows"
If UsedRange.Columns.Count < C_Count Then strMsg = "Columns"
If strMsg <> "" Then
MsgBox Target.Address & strMsg & " was deleted"
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
R_Count = UsedRange.Rows.Count
C_Count = UsedRange.Columns.Count
End Sub


__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Old May 4th, 2002, 07:53 PM   #6
Colo
MrExcel MVP
 
Colo's Avatar
 
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
Default

Hi Pinball, Are you still watching here?
Here is another way.


Option Explicit

Sub EventHack()
Dim lngId As Long
Dim CtrlCbc As CommandBarControl
Dim CtrlCbcRet As CommandBarControls

Set CtrlCbcRet = CommandBars.FindControls(ID:=478)
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = "DeletionMenuRouting"
Next CtrlCbc

Set CtrlCbcRet = CommandBars.FindControls(ID:=293)
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = "LineDeletionEventProcessingProc"
Next CtrlCbc
End Sub

Sub EventReset()
Dim lngId As Long
Dim CtrlCbc As CommandBarControl
Dim CtrlCbcRet As CommandBarControls

Set CtrlCbcRet = CommandBars.FindControls(ID:=478)
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = ""
Next CtrlCbc

Set CtrlCbcRet = CommandBars.FindControls(ID:=293)
For Each CtrlCbc In CtrlCbcRet
CtrlCbc.OnAction = ""
Next CtrlCbc
End Sub


Private Sub DeletionMenuRouting()
If Not TypeOf Selection Is Range Then Exit Sub
If Selection.Address = Selection.EntireRow.Address Then
Call LineDeletionEventProcessingProc
Else
Application.Dialogs(xlDialogEditDelete).Show
End If
End Sub

Private Sub LineDeletionEventProcessingProc()
MsgBox "Rows ware deleted"
Selection.Delete xlUp
End Sub

__________________
Regards,

Masaru Kaji aka Colo - Ex Microsoft MVP Since 2004 -2009
Colo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes