ignoring a sub routine

S

SU123

i have two subroutines
1. on double click insert a line using Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

2. on enter resize cells (as some of my cells are merged and autofit does
not work) - using rivate Sub Worksheet_Change(ByVal Target As Range) function.

The issue i have is when calling function/sub 1, function/sub 2 is
automatically activated and causes an error.
is there a way that i can have function/sub one ignore function/sub 2.

Thanx in advance
 
M

Mauro Gamberini

Try:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
'code
End Sub
 
S

SU123

this wont actually work, because the issue becomes, by calling the second sub
routine, the relative place of the cursor changes and this makes the routines
very complex.

i did give it a try, and received the same error - which is caused due to
the relative cell position.

any other ideas.
 
D

Dave Peterson

If you've turned on "edit directly in the cell", then you'll be editing the cell
after you doubleclick on that cell.

If you hit the Escape key, then your second procedure doesn't fire, right?

You can add a line to stop going into edit mode after the doubleclick.

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Cancel = True
'rest of code here
End Sub
 
S

SU123

Dave
i have that in the code already, but the issue occurs when i want to add a
new line.

when adding the new line, it checks the bolean, but as i select the cells to
copy and paste, it then tries to resize them (i.e. calls the 2nd procedure).

is there a way to add a bolean to the worksheet_change routine, as that i
believe would solve the issue.
 
S

SU123

thanx Bob that worked a treat!
Bob Phillips said:
Disable events

Application.EnableEvents = false

and reset to true after.

--
__________________________________
HTH

Bob
 
D

Dave Peterson

It's not the doubleclicking that causes the trouble. It's what your code does.

But Bob answered that!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top