+ Reply to Thread
Results 1 to 6 of 6

Understanding why the code works

  1. #1
    Registered User
    Join Date
    10-08-2014
    Location
    london
    MS-Off Ver
    2007
    Posts
    14

    Understanding why the code works

    Hi Below is some code, it does whats needed, but I want to understand why it works so I can adjust it as an when.

    Please Login or Register  to view this content.
    How does

    Please Login or Register  to view this content.
    work? also is the absolute address of cell B1 required as the code works with just the relative address, why is that important?

    Many thanks

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Understanding why the code works

    the Sub line tells the code to pass the cell reference that has changed into the variable Target

    so the line you're querying is basically saying "is target = A1?" or "is A1 the cell that has changed?"

    The $B$1 would work exactly the same in this instance as B1
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    10-08-2014
    Location
    london
    MS-Off Ver
    2007
    Posts
    14

    Re: Understanding why the code works

    Hi Thanks for the reply, So target.address is telling the code that CELL reference A1 is a now a variable?

    I'm looking at the code simplistically and still trying to work out how excel processes the information eg

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Understanding why the code works

    This is for changes on the sheet.
    Any cell you typing in the sheet is target cell.

    And code will be run whenever you change something.
    However, if you don't want rest of the code to be executed you can jump out of the Sub or skip it by IF function.

    In your case you will execute code only If Target.Address is "$A$1".

    That means for every other target address (i.e. B1) code will run, check is target address A1 and if not it will skip IF part of the code.

    only when typing in A1
    Please Login or Register  to view this content.
    will be True and IF will run within IF statement.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Understanding why the code works

    This is another approach when exiting sub:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-08-2014
    Location
    london
    MS-Off Ver
    2007
    Posts
    14

    Re: Understanding why the code works

    Thanks for the responses

+ 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] Need help understanding why this line of code works.
    By jbwitty in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-26-2013, 01:01 AM
  2. Understanding how this [formula] works
    By jmendenhall22 in forum Excel General
    Replies: 2
    Last Post: 05-24-2013, 08:47 PM
  3. does not understanding how it works
    By chngbh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2011, 01:03 AM
  4. Understanding How Counting Uniques Works
    By nothingisthis in forum Excel General
    Replies: 6
    Last Post: 04-02-2010, 01:58 PM
  5. understanding how FindFirst works.
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 03-05-2008, 05:46 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