+ Reply to Thread
Results 1 to 10 of 10

Worksheet Change Event Non Contiguous Range

  1. #1
    Registered User
    Join Date
    08-18-2020
    Location
    Kuala Lumpur
    MS-Off Ver
    MS Office 2019
    Posts
    28

    Worksheet Change Event Non Contiguous Range

    Hey guys, I am trying to write for a worksheet change event for two non contiguous range , which are cells A&lastrow and C&lastrow. For example, if lastrow=5, then it is A5, and C5, while excluding B5. This is my code, and it is not working, any idea on how to fix the syntax.


    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim lastrow As Long
    lastrow = 5


    If Not Intersect(Target, Range("A & lastrow, C & lastrow ")) Is Nothing Then
    MsgBox "Hello"

    End If
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Worksheet Change Event Non Contiguous Range

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-18-2020
    Location
    Kuala Lumpur
    MS-Off Ver
    MS Office 2019
    Posts
    28

    Re: Worksheet Change Event Non Contiguous Range

    Doesn't work. This is non contiguous range ,meaning B5 is to be excluded, your codes identify B5 as well .

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Worksheet Change Event Non Contiguous Range

    Does this do what you want?

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    08-18-2020
    Location
    Kuala Lumpur
    MS-Off Ver
    MS Office 2019
    Posts
    28

    Re: Worksheet Change Event Non Contiguous Range

    Hi Andy, nope doesn't solve it.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Worksheet Change Event Non Contiguous Range

    You need to provide more useful feed back.

    For me, if I select A5 and C5 and enter values in both cells at once using CTRL+ENTER it works.

    If I have both selected but only enter value into 1 cell, using Enter, then it does not work.
    If I select only 1 of the cells and enter it does not work.
    If I select more cells it does not work.

    Please explain the circumstances under which it should work

  7. #7
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Worksheet Change Event Non Contiguous Range

    Maybe it is just a very simple case, like :

    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  8. #8
    Registered User
    Join Date
    08-18-2020
    Location
    Kuala Lumpur
    MS-Off Ver
    MS Office 2019
    Posts
    28

    Re: Worksheet Change Event Non Contiguous Range

    Andy, I have made it very clear on my question. Non Contiguous. Should be understood that one of either A5 or C5 will be inputted, the worksheet change event will be fired.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Worksheet Change Event Non Contiguous Range

    To me, non contiguous means a reference to 2 or more cells.

    You simply mean 2 non adjacent cells

  10. #10
    Registered User
    Join Date
    08-18-2020
    Location
    Kuala Lumpur
    MS-Off Ver
    MS Office 2019
    Posts
    28

    Re: Worksheet Change Event Non Contiguous Range

    yes Andy.

    I have found the solution . Its as follows

    if not intersect(target,union(range("A" & lastrow),range("D"&lastrow))) is nothing then msgbox "hello"

+ 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] Execute Worksheet change event only within specific range
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2020, 11:31 AM
  2. [SOLVED] Worksheet change event if in range negative value find then higlight the value
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-20-2017, 05:24 AM
  3. [SOLVED] Worksheet change event to move values up over non-contiguous ranges (remove spaces)
    By L plates in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2016, 11:57 AM
  4. How to make a Worksheet Calculate event when a range of cells change?
    By Invicta084 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2014, 07:20 PM
  5. [SOLVED] need help setting range in worksheet change event
    By ShoshanaM in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2012, 04:07 PM
  6. Worksheet Change Event-change the range in my VBA
    By systemx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2006, 05:00 AM
  7. Worksheet Change Event-when a cell with a certain range of cells) are changed?
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-25-2005, 07:06 PM

Tags for this Thread

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