+ Reply to Thread
Results 1 to 8 of 8

How to make this macro work on different sheets

  1. #1
    Forum Contributor
    Join Date
    05-19-2012
    Location
    houston
    MS-Off Ver
    excel 2013
    Posts
    103

    How to make this macro work on different sheets

    Hi,

    I use the following macro in a userform to delete a selected row on sheet2. We are adding about 20 sheets to our workbook and I want to use the same macro on each of the new sheets. I know I can create a new userform with the macro for each of the 20 sheets and replace the "Sheet2" with the different sheet names.

    Instead of having to create 20 duplicate userforms/macros with the only difference being the Sheet name, is there a way to write this macro without the sheet name, so it works on any sheet that calls the userform?

    Each sheet will work independently from each other, different rows being deleted at different times on the different sheets... so putting all the sheet names in the array won't work.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: How to make this macro work on different sheets

    .
    Try :

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How to make this macro work on different sheets

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Incorporate code into your current code where you want to delete row in all sheets.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    05-19-2012
    Location
    houston
    MS-Off Ver
    excel 2013
    Posts
    103

    Re: How to make this macro work on different sheets

    Hey Logit,

    Thank you for the help... I tried your code change and when clicking the command button to run the macro and delete the row, it doesn't do anything. It will throw the error handler, so that still works. Any other ideas?

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: How to make this macro work on different sheets

    How about
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: How to make this macro work on different sheets

    Did I misunderstand what you want to do?
    I understood that you would have selected a cell, got the userform, did some stuff and now had to delete the same row where you selected in all sheets.
    Or do you want to delete a selected row in whatever sheet is open when you get the userform and not the others?

    Or if you open the UserForm as vbModeless you can select any cell/row while the UserForm is open and delete that cell/row

    Please Login or Register  to view this content.
    Last edited by jolivanes; 09-22-2019 at 10:58 AM. Reason: Added info

  7. #7
    Forum Contributor
    Join Date
    05-19-2012
    Location
    houston
    MS-Off Ver
    excel 2013
    Posts
    103

    Re: How to make this macro work on different sheets

    Thank you Fluff13 works great!

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: How to make this macro work on different sheets

    You're welcome & thanks for the feedback

+ 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. Make the same VBA code work for all sheets of the Workbook.
    By Francisco Sousa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-26-2015, 07:35 AM
  2. {DELETE}Make a single sheet macro work for all sheets in workbook
    By TwistedGhost in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 04:29 PM
  3. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  4. [SOLVED] A way to make a macro work on multiple sheets
    By WraithGhost in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-29-2012, 06:39 AM
  5. Make this macro work for all sheets in workbook
    By jonno in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2010, 07:16 AM
  6. How Can I make a Macro work to Hidden Sheets?
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-21-2009, 03:04 PM
  7. Make Macro work accross all active (grouped) sheets
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2009, 01:44 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