+ Reply to Thread
Results 1 to 4 of 4

Commandbutton Question.

Hybrid View

Steach91 Commandbutton Question. 01-24-2007, 11:27 AM
Steach91 No Help? - Is it even... 01-25-2007, 01:40 PM
Leith Ross Hello Steach91, Part of... 01-25-2007, 04:30 PM
Steach91 Fantastic! Sorry it took... 01-29-2007, 11:50 PM
  1. #1
    Registered User
    Join Date
    01-07-2006
    Posts
    26

    Commandbutton Question.

    I've got a couple of Commandbuttons, that I would like when clicked to determine the row it is located in.

    I have similar code for regular buttons, but can't seem to find a way to convert this to work with command buttons.

    Any help?

    Here is the code I have for the regular buttons.

        Dim b As Object, cs As Integer
        Set b = ActiveSheet.Buttons(Application.Caller)
        With b.TopLeftCell
            row = .row
        End With

  2. #2
    Registered User
    Join Date
    01-07-2006
    Posts
    26

    No Help? - Is it even possible?

    Appreciate any help

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Steach91,

    Part of your problem is you are using the wrong object class. The Buttons class is not the right one to use. There are 2 types of controls that can be placed on a worksheet: Forms Controls, and Control Toolbox Controls, also known as ActiveX. Here is the code for both.

    Public Sub ButtonRow()
      
        'Forms Controls Macro
         Btn = Application.Caller
         Row = ActiveSheet.Shapes(Btn).TopLeftCell.Row
      
    End Sub
    
    Private Sub CommandButton1_Click()
    
        'Control Toolbox Macro Code
         Set CmdBtn = ActiveSheet.OLEObjects("CommandButton1")
         Row = CmdBtn.TopLeftCell.Row
      
    End Sub
    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    01-07-2006
    Posts
    26
    Fantastic!

    Sorry it took me so long to reply, I haven't checked in lately. I had almost given up on it.... thankfully i hadn't coded a work around.

    Thanks a ton!

    works perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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