+ Reply to Thread
Results 1 to 3 of 3

Macro does not work from any selected cell on the spreadsheet

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Question Macro does not work from any selected cell on the spreadsheet

    I created a very simple macro, which actually works.

    There is a button on my spreadsheet, so the user can launch the macro using this button. So far so good.

    Please Login or Register  to view this content.
    At the moment the user clicks on the button, the part of the macro which is hiding the rows will not take place if the cell activated at the moment of launching the macro is in the range below :

    The table on my Excel sheet covers range A5:E49
    If the active cell is anywhere in A6:49 or C5:D24 or C25, the hiding part of the macro will not work. Launched from any other cells on the spreadsheet it works fine.

    The rest works fine and I am not getting an error.

    To solve this I just need to add the line Range("G9").Select and it will work.

    But I would like to understand why it does not work from the cells given above. My sheet is not protected and I unlocked the cells just ion case.

    Any ideas ? Thanks !

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro does not work from any selected cell on the spreadsheet

    I will do my best to try to explain. Cell is a variable range set by you while activecell is a static range which is selected in the worksheet. How you loop works is like this (if G9 is the selected cell):

    Step 1. Check if D8 and H9 is blank. If so hide all of row 8
    Step 2. Check if D9 and H9 is blank. If so hide all of row 9
    Step 3. Check if D10 and H9 is blank. If so hide all of row 10.
    etc to D49


    If the selected cell is a range in which the cell 1 column to the right has a value then no rows will be hidden.

    The code is working correct by doing exactly what you tell it to. I fear your understanding of what it is doing is flawed.

  3. #3
    Registered User
    Join Date
    11-20-2012
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Thumbs up Re: Macro does not work from any selected cell on the spreadsheet

    Thanks a lot for your answer. I understand exactly what is happening now. This is again a good example of seeing what we want to see. Thanks again !

+ 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. Generalize macro to work with any selected row
    By stash212 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2013, 05:16 PM
  2. A macro that makes all macros within the spreadsheet work
    By Ardiko in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 02:12 PM
  3. Replies: 6
    Last Post: 08-09-2013, 06:20 PM
  4. [SOLVED] In spreadsheet click on one cell and several are selected
    By Lou in forum Excel General
    Replies: 2
    Last Post: 05-04-2006, 11:25 AM
  5. [SOLVED] Macro to take selected cells times a selected cell
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2005, 08:05 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