+ Reply to Thread
Results 1 to 4 of 4

Define worksheet to run macro

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    Adelaide
    MS-Off Ver
    Excel 2016
    Posts
    31

    Define worksheet to run macro

    Hi All

    I have this code, but it runs in all worksheets. How to I adjust this so that it only runs on the selected range, but only in the worksheet I define? Ie, I only want it to run in worksheet called "Budget".

    Sub NoSpace()

    Dim sh As Worksheet
    For Each sh In Sheets
    sh.Range("O9:O500").Replace what:=" ", replacement:=""
    Next sh
    End Sub

    Cheers
    Isacael

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,986

    Re: Define worksheet to run macro

    Is this what you want:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-23-2009
    Location
    Adelaide
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: Define worksheet to run macro

    Perfect, thanks TMS. Another request... Can you add some code that will trigger this macro when user exits the cell?

    Cheers
    Isacael

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,026

    Re: Define worksheet to run macro

    If it is a selected range then you do not have to define the sheet...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ 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. Identify the value in worksheet one and define the same in worksheet 2
    By shakumxl in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-02-2020, 09:29 PM
  2. [SOLVED] define worksheet question
    By adamheon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2017, 01:22 PM
  3. Define Name or Worksheet to use?
    By calvinle in forum Excel General
    Replies: 6
    Last Post: 09-17-2014, 04:47 AM
  4. [SOLVED] Define contents entire worksheet
    By dspeters in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-09-2014, 02:53 AM
  5. [SOLVED] How to define a range in another worksheet ?
    By SelAli in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2014, 06:35 PM
  6. Define worksheet as variable, then call in macro
    By bugman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2005, 01:20 PM
  7. how can i define initial worksheet
    By Miqueias Lucas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2005, 02: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