+ Reply to Thread
Results 1 to 5 of 5

Placing a button programmatically on a worksheet

  1. #1
    Forum Contributor
    Join Date
    04-13-2011
    Location
    Havant, Hants, England
    MS-Off Ver
    Excel 2010
    Posts
    116

    Placing a button programmatically on a worksheet

    Hi,

    I have an expanding worksheet and would like to move a button so that it is always near the bottom of the worksheet data. When the button is pressed it reworks the worksheet and adds in some additional rows (up to 10 max). I'd like it so that the procedure also moves the button down keeping it in line with approximately the last row of data but not sure how to do this with vba... Any help / indicators greatly appreciated, thanks, Neil

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Placing a button programmatically on a worksheet

    Hi,
    It depends if your code is in a normal module or in a sheet module. Also it depends if it is ActiveX control or Form Control.

    For ActiveX control in a sheet module you can use any of the following to reference the control named CommandButton1 and it's the only on the sheet (i.e. index is 1):

    Please Login or Register  to view this content.

    If the code is in a normal module, replace Me. with reference to the sheet e.g. Worksheet(1). In this case you are not able to use Worksheet(1).CommandButton1. Use OLEobjects ot Shapes

    If it is a Form control named "Button 1" and the code is in a sheet module:

    Please Login or Register  to view this content.
    If the code is in a normal module, replace Me. with reference to the sheet e.g. Worksheet(1)


    Use Top and Left property to align the control with the desired cell e.g.

    Please Login or Register  to view this content.
    it will align the top left corner of the button with the top left corner of cell C5
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Contributor
    Join Date
    04-13-2011
    Location
    Havant, Hants, England
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Placing a button programmatically on a worksheet

    Hi buran , thanks for the reply. I'm using ActiveX buttons on worksheets referencing code in normal modules. I normally use the code
    Please Login or Register  to view this content.
    to find the last row so I assume I can use the reference to this to set the range as in your code above...
    Please Login or Register  to view this content.
    ? thanks, Neil

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Placing a button programmatically on a worksheet

    yep, it should work

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-13-2011
    Location
    Havant, Hants, England
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Placing a button programmatically on a worksheet

    Thanks, I'll give it a go & see how I fare! Many thanks for your help, Neil

+ 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. Programmatically placing data labels
    By jsmath22 in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 11-09-2009, 08:26 AM
  2. [SOLVED] Programmatically put an image on a button
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2006, 01:55 PM
  3. [SOLVED] add button to UserForm programmatically
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2006, 08:10 AM
  4. Placing action on a button!!
    By loopoo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2005, 08:54 AM
  5. how do i programmatically insert a button on a worksheet
    By Qaspec in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2005, 02: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