Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default intersect function problem

I am trying to get a couple of macros to run when a cell value changes. I can
get this to work but I have a problem caused by the selection of multiple
cells.

In the following code the macro delete_sheet works fine when a single cell
value in the keycells range is changed to 'No comment', however, the
add_sheet macro has part of its code which selects multiple cells in other
ranges and edits them. As soon as the add_sheet macro gets to this point I
get the error 'Run time error 13 - type mismatch'.

Same error occurs if multiple cells are selected manually and I try to edit
them.

The following code is embedded in the worksheet while the other 2 macros are
modules.

Any advice greatly appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range

Set KeyCells = Range("H11:H65536") ', Range("H11").End(xlDown))

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "No Comment" Then

delete_sheet

ElseIf Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "See Comments Provided" Then

add_sheet

End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default intersect function problem

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range
if Target.count = 1 then exit sub
Set KeyCells = Range("H11:H65536") ', Range("H11").End(xlDown))

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "No Comment" Then

delete_sheet

ElseIf Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "See Comments Provided" Then

add_sheet

End If
End Sub

Using Range(Target.Address) is like saying Range(Range("A1").Address) to
refer to cell A1.
In otherwords, just use Target since it is a reference to a range. Same as
if you did

set Target = Range("A1")

--
Regards,
Tom Ogilvy






"pumpbhoy" wrote in message
...
I am trying to get a couple of macros to run when a cell value changes. I

can
get this to work but I have a problem caused by the selection of multiple
cells.

In the following code the macro delete_sheet works fine when a single cell
value in the keycells range is changed to 'No comment', however, the
add_sheet macro has part of its code which selects multiple cells in other
ranges and edits them. As soon as the add_sheet macro gets to this point I
get the error 'Run time error 13 - type mismatch'.

Same error occurs if multiple cells are selected manually and I try to

edit
them.

The following code is embedded in the worksheet while the other 2 macros

are
modules.

Any advice greatly appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range

Set KeyCells = Range("H11:H65536") ', Range("H11").End(xlDown))

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "No Comment" Then

delete_sheet

ElseIf Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "See Comments Provided"

Then

add_sheet

End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default intersect function problem

Thanks for this. I have got it working ok now.

"Tom Ogilvy" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range
if Target.count = 1 then exit sub
Set KeyCells = Range("H11:H65536") ', Range("H11").End(xlDown))

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "No Comment" Then

delete_sheet

ElseIf Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "See Comments Provided" Then

add_sheet

End If
End Sub

Using Range(Target.Address) is like saying Range(Range("A1").Address) to
refer to cell A1.
In otherwords, just use Target since it is a reference to a range. Same as
if you did

set Target = Range("A1")

--
Regards,
Tom Ogilvy






"pumpbhoy" wrote in message
...
I am trying to get a couple of macros to run when a cell value changes. I

can
get this to work but I have a problem caused by the selection of multiple
cells.

In the following code the macro delete_sheet works fine when a single cell
value in the keycells range is changed to 'No comment', however, the
add_sheet macro has part of its code which selects multiple cells in other
ranges and edits them. As soon as the add_sheet macro gets to this point I
get the error 'Run time error 13 - type mismatch'.

Same error occurs if multiple cells are selected manually and I try to

edit
them.

The following code is embedded in the worksheet while the other 2 macros

are
modules.

Any advice greatly appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range

Set KeyCells = Range("H11:H65536") ', Range("H11").End(xlDown))

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "No Comment" Then

delete_sheet

ElseIf Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing And Range(Target.Address) = "See Comments Provided"

Then

add_sheet

End If
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get the intersect cell data out using vba or function mango Excel Worksheet Functions 1 December 30th 04 09:46 AM
Opposite of Intersect function - an example DataFreakFromUtah Excel Programming 1 September 17th 04 11:30 PM
Syntax problem with" intersect" Imbecill[_2_] Excel Programming 2 May 29th 04 06:38 PM
Intersect Formula??? scrabtree[_2_] Excel Programming 3 October 15th 03 08:30 PM
Help with If Not Intersect derek Excel Programming 6 July 11th 03 04:39 PM


All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"