+ Reply to Thread
Results 1 to 3 of 3

macro that auto adjusts height of cells does not work when run with command button

  1. #1
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    macro that auto adjusts height of cells does not work when run with command button

    I found this great macro which adjusts the height of cells when a worksheet is activated (see macro below). I would like to activate the macro from a command button on a different worksheet within the same workbook, but I cannot get it to work. I tried adding the macro to a "Private Sub CommandButton1_Click()" function and included a line to activate the correct worksheet but it doesn't seem to work


    THE ORIGINAL CODE THAT WORKS
    Please Login or Register  to view this content.
    THE UPDATED CODE THAT DOESN"T WORK

    Please Login or Register  to view this content.

  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
    44,083

    Re: macro that auto adjusts height of cells does not work when run with command button

    Put the body of the code into a free standing standard module. Then call the new subroutine from the Sheet Activate or from the Command Button.

    That way, you only have to maintain one set of code.

    Regards, TMS
    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
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    Re: macro that auto adjusts height of cells does not work when run with command button

    Thank you!

    I saved the body of this macro to Module 1 and changed the line "Private Sub worksheet_activate()" to "sub auto_resize()" then added the following code to the command button located on another worksheet and it worked:

    Please Login or Register  to view this content.

+ 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] Command button with macro does not work correctly
    By c_spooner1999 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-01-2013, 11:22 AM
  2. Macro Doesn't Work With Command Button
    By jbmerrel in forum Excel General
    Replies: 4
    Last Post: 03-14-2012, 03:53 PM
  3. Row height adjusts on sort
    By bld in forum Excel General
    Replies: 0
    Last Post: 04-19-2007, 05:56 PM
  4. Replies: 0
    Last Post: 10-21-2005, 10:05 AM
  5. [SOLVED] Assign Macro to Command Button doesn't work
    By CLS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2005, 01: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