+ Reply to Thread
Results 1 to 7 of 7

Limit a macro to only run when certain cells are selected

  1. #1
    Registered User
    Join Date
    12-02-2014
    Location
    Grand Rapids, MI
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Limit a macro to only run when certain cells are selected

    I have a code for a department calendar so when you select a week number and click a button, it autofills the schedule for the week. It works great and my boss loves it, but because it uses relative referencing, it will create little autofill disasters if the wrong cell is selected.

    I'm looking for a code that will limit it to only work when specific cells are selected:

    (B4, B15, B26, B37, B48, B59, B70, B81, B92, B103, B114, B125, B136, B147, B158, B169, B180, B191, B202, B213, B224, B235, B246, B257, B268, B279, B290, B301, B312, B323, B334, B345, B356, B367, B378, B389, B400, B411, B422, B433, B444, B455, B466, B477, B488, B499, B510, B521, B532, B543, B554, B565, B576)

    Here's the code I have now:

    Please Login or Register  to view this content.
    I found an earlier thread with a similar problem, but not quite close enough for my simple mind to connect the dots:
    http://www.excelforum.com/excel-prog...-selected.html

    Thanks in advance for any help you awesome people can give.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Limit a macro to only run when certain cells are selected

    try this instead:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Limit a macro to only run when certain cells are selected

    Or you could try this:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-02-2014
    Location
    Grand Rapids, MI
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Limit a macro to only run when certain cells are selected

    Works perfectly, thank you!

    I'm wondering, what would the code to specify a range of cells look like?
    Last edited by lptubez; 12-03-2014 at 11:53 AM.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Limit a macro to only run when certain cells are selected

    You could modify my second code above or

    use the intersect function if you have a range.



    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-03-2014 at 02:30 PM.

  6. #6
    Registered User
    Join Date
    12-02-2014
    Location
    Grand Rapids, MI
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Limit a macro to only run when certain cells are selected

    Thank you again!

    [QUOTE=mehmetcik;3918539]You could modify my second code above or

    use the intersect function if you have a range.QUOTE]

  7. #7
    Registered User
    Join Date
    12-02-2014
    Location
    Grand Rapids, MI
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    4

    Re: Limit a macro to only run when certain cells are selected

    Thanks again! I wasn't very clear. This is for a different macro in the same workbook and I'm having trouble adapting the code to it. I am very new to this, and thought that if I could see how to do it once I would be able to figure it out, but apparently not!

    If you can show me how to make the following macro run only if a cell in D6:H15 or D19:H28 is selected, I think I can figure it out from there.

    Please Login or Register  to view this content.


    Quote Originally Posted by mehmetcik View Post
    You could modify my second code above or

    use the intersect function if you have a range.

+ 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] edit a macro that will limit the range of cells being copied in the email body
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-16-2013, 10:45 AM
  2. Limit Maximum Items Selected in VBA Listbox
    By jrkujak in forum Excel General
    Replies: 2
    Last Post: 11-09-2011, 12:42 PM
  3. Replies: 2
    Last Post: 08-28-2011, 02:39 AM
  4. Limit macro to only run if certain cells are selected
    By Mayweed in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 09-01-2010, 08:59 PM
  5. 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

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