+ Reply to Thread
Results 1 to 3 of 3

Have macro run on a single worksheet

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Have macro run on a single worksheet

    Hi everyone,

    I have the following code:

    Please Login or Register  to view this content.
    This macro is assigned to a userform button located in different worksheets. All I want is for this macro to be run only in the XXX Data worksheet, even though the button is located in a different worksheet. For some reason, the macro keeps try to read the worksheet that the button is located on first before moving to the XXX data worksheet.

    Any ideas?

    Thanks!!!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Have macro run on a single worksheet

    Hi Groovicles,

    This might be an easy answer but we'd need to see the whole macro to insure it is.

    Instead of your line of:
    Range("B1:IV1500").Select
    try
    .Range("B1:IV1500").Select

    By putting a period in front of the "Range" it uses the "With" location instead of the active sheet.

    I'm not sure this is the answer but give it a try.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Have macro run on a single worksheet

    Hi

    Hi,

    You can't select a range on a sheet that isn't the active sheet. You can do stuff like Copy but not Select. Even with Copy you would have to put a . in front of the Range("B1.... instruction.

    To use the code you have you would need to Activate the XXX worksheet first (and then you wouldn't need the With statement.

    But it's it's generally bad practice to use .Select & .Activate. Better to create a range object variable and use that object in any subsequent YYY procedure you are calling.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  2. [SOLVED] Macro below specific to a single Worksheet?
    By MIGARDEIN in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2015, 02:06 PM
  3. Macro to Copy data to a new worksheet based on the value of a single cell
    By apdown10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2014, 03:13 PM
  4. Macro to copy tables from specific worksheets into a single worksheet.
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-12-2013, 09:07 AM
  5. [SOLVED] Macro to save single worksheet as PDF. Filename based on cell.
    By adam.hewitt5 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2012, 05:21 PM
  6. [SOLVED] Macro to replace every single cell in each worksheet with values only
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2012, 10:42 AM
  7. Activating a worksheet with a daily changing name, using a single macro
    By Sccye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2010, 11:06 AM

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