Thread: Insert macro
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default Insert macro

Calculate event shouldn't be placed in a normal module!

In VBA Prpject Explorer right click on sheet name you want to apply
Calculate event on! from the local menu choose View code! From Objects (left
dropdown list) choose Worksheet! From Procedures (right dropdown list) choose
Calculate!

Regards,
Stefi

€˛Subhojeet€¯ ezt Ć*rta:

Hi
I have written the following code in module 1 to capture calculate event.
But this is not working

Private Sub Calculate()
Dim rngCurrent As Range
Set rngCurrent = ActiveCell

ActiveSheet.Rows(rngCurrent.Row & ":" &
rngCurrent.Row).Interior.ColorIndex = 6


End Sub

Please tell me what to do next. I am great turmoil.
Thanks

"Stefi" wrote:

Unfortunately there is no Insert event. As far as I know the only event
triggered by inserting a row is Calculate event, but if you want to
distinguish between row inserting and other events also triggering Calculate
event you have to apply other programming tricks, e.g. maintain a global
variable (say NoOfRows) storing No of rows and compare it to actual No of
rows in Calculate event sub. If actual No of rows is greater then NoOfRows
then add 1 to NoOfRows and do what you need in case of inserting. This is
only an idea, you have to try wether it works or not.

Perhaps real XL gurus know a better way!?

Regards,
Stefi


"Subhojeet" wrote:

Thanks for the reply but to use the below mentioned code I need to write a
sub routine. But I want this to happen the moment someone inserts a new row,
maybe by right clicking on the worksheet and select "Insert" from the pop up
menu. I guess I need to capture the Insert event. How do I do that?
Thanks

"Stefi" wrote:

Selection.EntireRow.Insert
ActiveCell.EntireRow.Interior.ColorIndex = 6

Regards,
Stefi

€˛Subhojeet€¯ ezt Ć*rta:

Hello,

I want to write a macro where on inserting a new row in the active
worksheet, the newly inserted row will become yellow in color. But I dont
know how to do this. kindly help

Thanks