Results 1 to 7 of 7

Limit a macro to only run when certain cells are selected

Threaded View

lptubez Limit a macro to only run... 12-02-2014, 06:54 PM
mehmetcik Re: Limit a macro to only run... 12-02-2014, 07:15 PM
lptubez Re: Limit a macro to only run... 12-03-2014, 09:45 AM
mehmetcik Re: Limit a macro to only run... 12-02-2014, 07:28 PM
mehmetcik Re: Limit a macro to only run... 12-03-2014, 02:22 PM
lptubez Re: Limit a macro to only run... 12-03-2014, 03:11 PM
lptubez Re: Limit a macro to only run... 12-03-2014, 04:07 PM
  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:

    Sub FillSelectedWeek()
    '
    ' FillSelectedWeek Macro
    '
    
    '
        ActiveCell.Offset(2, 1).Range("A1:A8").Select
        Selection.AutoFill Destination:=ActiveCell.Range("A1:F8"), Type:= _
            xlFillValues
        ActiveCell.Range("A1:F8").Select
        ActiveCell.Offset(0, 1).Range("A1:E8").Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
        End With
    End Sub
    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

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