+ Reply to Thread
Results 1 to 5 of 5

Worksheet_Change Event - Target.Name.Name error in certain situations

  1. #1
    Registered User
    Join Date
    04-13-2012
    Location
    Leeds, UK
    MS-Off Ver
    Excel 2007
    Posts
    46

    Worksheet_Change Event - Target.Name.Name error in certain situations

    I'm a newbie to VBA so apologies for any daft code, I'm learning one error at a time.

    The following code is supposed to copy the contents of a changed cell to the associated cell in 'Wkg - Comments' sheet (if user wants to save the changes) or reset the cell to existing value from 'Wkg - Comments'. It works fine if the user presses the Enter key or clicks the Enter tick button by the formula bar.

    It doesn't work if the user presses the Delete key, or uses Ctrl+Enter - it then throws up an 'Application-defined or object-defined' error on the line 36 (I think): "strCellName = Target.Name.Name".

    Please Login or Register  to view this content.

    My original attempt looked like as follows, and the error appeared at "CommentColumn = CommentDBColumn(Target.Name.Name)"

    Please Login or Register  to view this content.

    Why does the error occur with 'Delete' and Ctrl+Enter? Does Worksheet_Change behave differently for some reason? I've tried to examine Target.Name.Name on a separate spreadsheet to see what's happening, and that seems to show that it always passes a string in any situation. What am I missing?


    CommentDBColumn() is in Module1, but with my amendment above it appears the error is occurring before it is being called. Here it is just in case:

    Please Login or Register  to view this content.
    Last edited by GazP; 07-16-2013 at 12:12 PM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Worksheet_Change Event - Target.Name.Name error in certain situations

    you would get an error if the cell is not named, or if you change more than one cell at a time-in which case you need to loop through the cells and process each one in turn
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    04-13-2012
    Location
    Leeds, UK
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Worksheet_Change Event - Target.Name.Name error in certain situations

    The cells are definitely named. I'm fairly sure only one cell is being changed in the process as only one cell is selected, however I will test and check.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Worksheet_Change Event - Target.Name.Name error in certain situations

    you mentioned ctrl+enter which is typically only used for entering the same information into multiple cells at once, and delete is often used on multiple cells

  5. #5
    Registered User
    Join Date
    04-13-2012
    Location
    Leeds, UK
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Worksheet_Change Event - Target.Name.Name error in certain situations

    You're absolutely right, it's treating it differently between changes that affect 1 cell and changes that affect >=1 cells. Changing the line to
    Please Login or Register  to view this content.
    has solved it.

    Many thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. capture the name of the target passed into Worksheet_Change event
    By Isabel Lopatin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2013, 01:06 AM
  2. [SOLVED] Worksheet_Change(ByVal Target As Range) - set to only update when 3 target cells changed?
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2012, 06:40 PM
  3. Worksheet_CHange (ByVal Target as Range) when target is formula cell
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 07:00 PM
  4. Error when Target Range is block, not cell in Worksheet_Change Eve
    By Jim Zeeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2006, 03:20 PM
  5. [SOLVED] Prevent error when deleting row within Worksheet_Change target ran
    By Peter Rooney in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2006, 11:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1