Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Identifying the type of a Worksheet_Change

Good morning all,

Is there any way of identifying the type of a worksheet change.
I have such an event macro in a database that sets validation on cells in a
column, based on the value of the cell in the column to the left.
This works fine, but if I delete a row, .target doesn't have anything to act
on.
I need to be able to tell Excel to run the event macro if a change has been
made to a cell, but not to the structure of the workbook itself.

Is there any way in which I can do this?

I tried a condition with .target.cells.count, but this doesn't seem to be
quite what I need.

Thanks in advance

Pete

  #2   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Identifying the type of a Worksheet_Change

Well, sounds like at least for the condition provided, (deletion of a row)
that you need to know how many rows contain data before and after the
deletion. If there is a difference in that number, then you don't want to
perform the actions of the macro. As for other structural changes, you would
still have the concern of moving a cell from one location to another, if a
cell containing say data A is moved to a cell that must contain data of
type/value B, then there would be a problem and you would most likely want
your macro run. One problem with this aspect, is that if you have determined
that number of rows, and this piece of data was the only item in the last
row, then by the comparison of number of rows, the validation would not be
run. *smirk* So definetly a trade off.



"Peter Rooney" wrote:

Good morning all,

Is there any way of identifying the type of a worksheet change.
I have such an event macro in a database that sets validation on cells in a
column, based on the value of the cell in the column to the left.
This works fine, but if I delete a row, .target doesn't have anything to act
on.
I need to be able to tell Excel to run the event macro if a change has been
made to a cell, but not to the structure of the workbook itself.

Is there any way in which I can do this?

I tried a condition with .target.cells.count, but this doesn't seem to be
quite what I need.

Thanks in advance

Pete

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Identifying the type of a Worksheet_Change

Thanks for your thoughts.
I was originally getting round the problem by running a FOR loop on all the
values in the column, but, although it worked and it wasn't taking too long,
it didn't seem to be the best way to go about things.
I was obviously wrong! :-)

Regards

Pete



"GB" wrote:

Well, sounds like at least for the condition provided, (deletion of a row)
that you need to know how many rows contain data before and after the
deletion. If there is a difference in that number, then you don't want to
perform the actions of the macro. As for other structural changes, you would
still have the concern of moving a cell from one location to another, if a
cell containing say data A is moved to a cell that must contain data of
type/value B, then there would be a problem and you would most likely want
your macro run. One problem with this aspect, is that if you have determined
that number of rows, and this piece of data was the only item in the last
row, then by the comparison of number of rows, the validation would not be
run. *smirk* So definetly a trade off.



"Peter Rooney" wrote:

Good morning all,

Is there any way of identifying the type of a worksheet change.
I have such an event macro in a database that sets validation on cells in a
column, based on the value of the cell in the column to the left.
This works fine, but if I delete a row, .target doesn't have anything to act
on.
I need to be able to tell Excel to run the event macro if a change has been
made to a cell, but not to the structure of the workbook itself.

Is there any way in which I can do this?

I tried a condition with .target.cells.count, but this doesn't seem to be
quite what I need.

Thanks in advance

Pete

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Identifying the type of a Worksheet_Change


the .target will not refer to anything when the row, cell or column has
been deleted. This is your indication that the structure has changed.

to test for this you can use
if .target is nothing then
'row/col deleted
else
'do your stuff
end if


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=501980

  #5   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Identifying the type of a Worksheet_Change

There is another way that is "quicker" from what I gather... It uses the
xLUp function. If you search either with my user name (GB) or xlup, you
should see a recent example of something that returns the last row of column
using built in Excel commands (also quoted in here as being faster than a for
loop.) But we are talking about micro seconds provided you are not using all
65 thousand + rows.

"Peter Rooney" wrote:

Thanks for your thoughts.
I was originally getting round the problem by running a FOR loop on all the
values in the column, but, although it worked and it wasn't taking too long,
it didn't seem to be the best way to go about things.
I was obviously wrong! :-)

Regards

Pete



"GB" wrote:

Well, sounds like at least for the condition provided, (deletion of a row)
that you need to know how many rows contain data before and after the
deletion. If there is a difference in that number, then you don't want to
perform the actions of the macro. As for other structural changes, you would
still have the concern of moving a cell from one location to another, if a
cell containing say data A is moved to a cell that must contain data of
type/value B, then there would be a problem and you would most likely want
your macro run. One problem with this aspect, is that if you have determined
that number of rows, and this piece of data was the only item in the last
row, then by the comparison of number of rows, the validation would not be
run. *smirk* So definetly a trade off.



"Peter Rooney" wrote:

Good morning all,

Is there any way of identifying the type of a worksheet change.
I have such an event macro in a database that sets validation on cells in a
column, based on the value of the cell in the column to the left.
This works fine, but if I delete a row, .target doesn't have anything to act
on.
I need to be able to tell Excel to run the event macro if a change has been
made to a cell, but not to the structure of the workbook itself.

Is there any way in which I can do this?

I tried a condition with .target.cells.count, but this doesn't seem to be
quite what I need.

Thanks in advance

Pete



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Identifying the type of a Worksheet_Change

Hi, GB

I already have my range defined, using .currentregion, but I'll take a look
at your code example anyway.
Thanks a lot for your help

Pete



"GB" wrote:

There is another way that is "quicker" from what I gather... It uses the
xLUp function. If you search either with my user name (GB) or xlup, you
should see a recent example of something that returns the last row of column
using built in Excel commands (also quoted in here as being faster than a for
loop.) But we are talking about micro seconds provided you are not using all
65 thousand + rows.

"Peter Rooney" wrote:

Thanks for your thoughts.
I was originally getting round the problem by running a FOR loop on all the
values in the column, but, although it worked and it wasn't taking too long,
it didn't seem to be the best way to go about things.
I was obviously wrong! :-)

Regards

Pete



"GB" wrote:

Well, sounds like at least for the condition provided, (deletion of a row)
that you need to know how many rows contain data before and after the
deletion. If there is a difference in that number, then you don't want to
perform the actions of the macro. As for other structural changes, you would
still have the concern of moving a cell from one location to another, if a
cell containing say data A is moved to a cell that must contain data of
type/value B, then there would be a problem and you would most likely want
your macro run. One problem with this aspect, is that if you have determined
that number of rows, and this piece of data was the only item in the last
row, then by the comparison of number of rows, the validation would not be
run. *smirk* So definetly a trade off.



"Peter Rooney" wrote:

Good morning all,

Is there any way of identifying the type of a worksheet change.
I have such an event macro in a database that sets validation on cells in a
column, based on the value of the cell in the column to the left.
This works fine, but if I delete a row, .target doesn't have anything to act
on.
I need to be able to tell Excel to run the event macro if a change has been
made to a cell, but not to the structure of the workbook itself.

Is there any way in which I can do this?

I tried a condition with .target.cells.count, but this doesn't seem to be
quite what I need.

Thanks in advance

Pete

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Identifying the type of a Worksheet_Change

Tony,

This is definitely putting me on the right track, although there's still
some way to go.

Thanks a lot for your help

Pete



"tony h" wrote:


the .target will not refer to anything when the row, cell or column has
been deleted. This is your indication that the structure has changed.

to test for this you can use
if .target is nothing then
'row/col deleted
else
'do your stuff
end if


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=501980


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
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Adding new 'Type' to Format->Number->Time->Type Chip Pearson Excel Discussion (Misc queries) 5 September 26th 05 08:45 PM
Identifying a Control Type Chrissy[_4_] Excel Programming 5 July 30th 03 08:25 AM
worksheet_change vs. calculate, and worksheet_change not running Tom Ogilvy Excel Programming 1 July 14th 03 02:51 AM
worksheet_change vs. calculate, and worksheet_change not running Ross[_5_] Excel Programming 0 July 13th 03 04:27 PM


All times are GMT +1. The time now is 11:36 AM.

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"