Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2006, 05:19 PM
Authorized User
 
Join Date: Dec 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default select cell directly underneath command button

how do i code a command button so that no matter what the active cell is, when the button is clicked, the cell that the command button is positioned in gets selected. by the way, the button ultimately adds another line somewhere above itself so the button will not always be in the exact same cell. thanks

 
Old April 19th, 2006, 04:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You need to use the TopLeftcell property of the CommandButton. The following code is written on the assumption that the command button is contained within one cell, if it is in more than one cell then you may need to modify as appropriate
Code:
Private Sub cmdTest_Click()

Dim i As Long

    cmdTest.TopLeftCell.Select

    i = cmdTest.TopLeftCell.Row
    ActiveSheet.Rows((i - 1) & ":" & (i - 1)).Insert Shift:=xlDown

End Sub
HTH,
Maccas






Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a button to a cell hewstone999 Access VBA 2 June 4th, 2008 07:23 AM
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
How to store "SELECT" command value? venkikrao VB.NET 1 March 16th, 2006 06:01 AM
Select Command jaucourt ADO.NET 8 January 28th, 2004 11:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.