+ Reply to Thread
Results 1 to 11 of 11

Code not recognising Target cell

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Code not recognising Target cell

    If the User selects a Product from the DropLists in E6 - E10, Code should find matching product in Col M and copy the Col N value to Col F

    Else if the User changes a price in F6 - F10, Code should find matching product in Col M and copy the Col F value to Col N.

    Please Login or Register  to view this content.
    For some reason it isn't identifying the relevant Match in Col M.

    Hope someone can see where it's going awry?

    All solutions, suggestions and alternatives welcome as ever

    Ochimus
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,234

    Re: Code not recognising Target cell

    Please Login or Register  to view this content.
    Last edited by sintek; 05-22-2020 at 01:33 PM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this …


    The Dim statement does not need here to be at the top of the module for global variables,
    must be in the event procedure …
    ActiveSheet is useless as a worksheet event raises only on the active sheet !
    Some logic errors or no sense after, the reason why the code can't work …

    According to your attachment the revamped event procedure :

    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
        
    Dim R
        
    If Target.CountLarge 1 Then Exit Sub
        
    If Intersect([E6:F10], TargetIs Nothing Or IsEmpty(TargetThen Exit Sub
        R 
    Application.Match(Target(1, -(Target.Column 5)), [Product], 0):  If IsError(RThen Exit Sub
        Application
    .EnableEvents False
        
    If Target.Column 5 Then Target(12) = Cells(114).Value2 Else Cells(114) = Target.Value2
        Application
    .EnableEvents True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-22-2020 at 07:29 PM. Reason: optimization according to the named range and IsError is back ‼

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Code not recognising Target cell

    This change event (replaces ALL of the code in your current module) seems to work...
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code not recognising Target cell

    Many thanks to each for the prompt response and solutions,

    Can now mark this as Solved.

    Ochimus

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Code not recognising Target cell


    Hi Rick,

    according to the initial post you forgot the event on column F …

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Code not recognising Target cell

    Tell me Marc, why doesn't this forum have a "bang head" Smiley... it would be so appropriate for me to use right now instead of this one. I completely missed that part of the question. Here is my code approach revised to handle the whole question that the OP asked...
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Code not recognising Target cell


    Maybe you could use the existing named range for column M like I did when I amended my code.

    What may happen with your last code if a cell in E6:F10 is cleared via the Del key for example ? …

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,234

    Re: Code not recognising Target cell

    Pleasure...Glad to have contributed...tx for rep +

  10. #10
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Code not recognising Target cell

    Quote Originally Posted by Marc L View Post
    What may happen with your last code if a cell in E6:F10 is cleared via the Del key for example ? …
    My head is just somewhere else of late. We are moving next week and most of my time is involved with packing so my volunteer time is done during in-between times which doesn't leave a lot of time for coding and checking code. The OP has your answer and appears happy with it so I'll just leave it there for now.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code not recognising Target cell


    « Bon courage » for your packing and later your moving …

+ 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. [SOLVED] Code not recognising last used column in row range
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-28-2019, 06:27 PM
  2. Code to write target cell values to cells in a specific Worksheet?
    By patdools in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-13-2019, 01:45 PM
  3. [SOLVED] how to make my code work with target.column instead of target.address
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-18-2017, 09:29 AM
  4. Timestamp beneath target cell when target cell's value changes based on calculation.
    By arwebb0264 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-15-2016, 06:31 PM
  5. [SOLVED] VBA code not recognising selected option button
    By Harribone in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2015, 10:07 AM
  6. Replies: 5
    Last Post: 01-22-2013, 11:38 AM
  7. Allow entry in target.cell and exceute code once
    By excel_vb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2010, 02:34 PM

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