+ Reply to Thread
Results 1 to 5 of 5

Set Button as ActiveCell

  1. #1
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Set Button as ActiveCell

    Hi all,

    After having been helped at one part of my project, I am now stuck at another one. Please have a look at the attachment (I have tried to keep it as simple as possible by removing everything not related). "Button1" triggers the creation of the buttons

    The final file will contain an unknown amount of rows/columns, with, as header, ID / TEXT1 / TEXT2 / TEXT... (Around 300k cells total)
    The final user will have to count how many words are in the cells of a specific column (he may need to do it for other columns as well).

    My approach is the following:

    1-Find the header, and convert each of its cells into individual buttons (one per column, each button automatically fitting in the cell)
    Sub Create_Buttons()
    -->Done, an issue may exist

    2- When the user click on one of these buttons, a column is added on the right, each cell being filled up with the number of words in the cell on the right (thank you for the previous help)
    Sub WordsPerCell_Button()
    -->Partially done

    Problem:

    When I click on a "TEXT..." button, I expected this button to become the ActiveCell, so that:
    - the length of the column would be measured (no empty cell)
    - the rank of the column would be picked up before inserting a column to its right

    Now, it is not working this way. ActiveCell is actually the one selected before clicking on the button.
    I've found on the forum and the help several references to SetFocus and TakeFocusOnClick, but I have not been able to use them properly so that the ActiveCell will be the one with the button.

    Any help would be very much appreciated.
    Thank you.
    WordsPerCell.xlsm

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Set Button as ActiveCell

    you don't need creating buttons, you can use Worksheet_SelectionChange event to get the same result.
    If you want buttons try this code
    Please Login or Register  to view this content.
    Last edited by patel45; 06-28-2014 at 12:36 PM.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: Set Button as ActiveCell

    Thank you for your answer, and my apologies for not replying earlier (I didn't have time to make your code working in my project before, and I didn't want to answer before giving it a serious try)

    I am new at VBA, and Worksheet_SelectionChange appears to be well above my current level.

    I still have mostly issues to understand the code that you have suggested, but after several testing I have finally succeeded to include it and to have it working as intended. At least, I am confident that with some more practice I should be able to understand it.
    I have 2 more questions, if you would be kind enough to answer them:

    1-With TopLeftCell, are you calling an object and looking for the TopLeftCell cell of this object, which is in this case the one cell with the button?

    2- What would be the proper declaration of "b"?

    Thank you again!

    Note: I have included a newer version of my test file, for the record, which includes your code in case somebody would need it.
    WordsPerCell2.xlsm

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Set Button as ActiveCell

    1) i did not understand your question
    2) dim b as Object

  5. #5
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: Set Button as ActiveCell

    1-Help provides the following explanation:

    OLEObject.TopLeftCell Property (Excel)
    Returns a Range object that represents the cell that lies under the upper-left corner of the specified object. Read-only.
    Please Login or Register  to view this content.
    From what I understand with this code:

    a-Set b is used to call an application for buttons.

    b-The application is defined as being TopLeftCell

    c-Based on the Help, I understand that the cell that lies under the upper-left corner of the specified object is the exact one where the button is, since the buttons fits the cell.

    My apologies if my wording is inaccurate or wrong, I am not a programmer at all
    Thank you again!

+ 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. Including Activecell value in caption of a Command Button
    By PaulC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2013, 02:24 PM
  2. activecell reference from command button
    By bangdakuan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2009, 07:26 PM
  3. ActiveCell and command button help
    By clownfish in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2009, 02:19 PM
  4. [SOLVED] how to know be button in activecell
    By x taol in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2006, 09:55 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