+ Reply to Thread
Results 1 to 4 of 4

Returning Activecell when pressing a button

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

    Returning Activecell when pressing a button

    Hi,

    Still a newbie regarding VBA, I have searched Google for 2 days without finding an answer to the issue below. In the example attached, I have aggregated pieces of codes found here and there but I have 1 main and 2 smaller issues left.

    My final goal is different from the example attached; I have just created a simpler version focused on the issue. In this example, I would like to color the column where the button is present. Problem is that I have to select a cell in the column before, instead of just clicking the button.

    How the example works:
    In "Tools", press the picture Temporary. This will:
    1-Create a "ToCheck" sheet
    2-Copy the data from "TEMP" to "ToCheck", inserting an intermediary column (i+1) after each column source (i)
    3-Select in the first row the cells i and i+1, then creating a button matching the size of the 2 cells
    4-Write the identical code for each different button (coloring the column)


    1: I had to do that for an unknown reason. "TEMP" results originally from an import that I don't control, and if I don't work on a copy then the macro will take a very long time to run (I guess due to the formatting of the source file)

    2&3: This is a very irritating part. To make things simpler, I tried to rewrite the macro by removing the intermediary column. But by doing so, then the buttons are created but they don't work at all! ...and I can't figure out why.

    Problems:
    -My main one how should the code be modified to color the 2 columns of the pressed button?

    -If I want to reset the file by inserting the line "Sheets("ToCheck").Delete", it doesn't work even if I confirm the request. What have I understood wrongly?

    -It is nowhere in the file, but I have also been looking for a way to reset the Private sub commands created for each button. In my master file, I can run the original macro several times, which will therefore create duplicated "Private Sub Button_XX_Click()" commands and will generate issues. Currently, I have to select and erase the code manually Is there a way (and I am sure that there is one) to reset the code with a command?

    I have tried to make things as easy as I could, I hope that it will be enough.
    Thank you for your time.

    ForumTestButton.xlsm

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Returning Activecell when pressing a button

    Sorry, I'm confused.

    What, in simple terms, are you trying to do?
    If posting code please use code tags, see here.

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

    Re: Returning Activecell when pressing a button

    My apologies. I guess that while trying to make things easier, I provided too many information.

    In "ToCheck", I would like to color the 2 columns where is located the created button (Pressing the button over C1D1 should color columns CD). Right now, it will color the column of the last selected cell and the following one.

    Thank you!

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

    Re: Returning Activecell when pressing a button

    I made some progress on this issue. I am going to try to explain what I did, and I apologize in advance if this is not clear

    -Buttons are automatically created in the first row. Each button has a macro attached to color a column.
    -The ultimate goal is to color the column where is located the pressed button.
    -Since activecell doesn't return the column of the button but the column of the last selected cell, I have added a value inside each macro, corresponding to the column of the button when this one was created.
    Please Login or Register  to view this content.
    ...and that's where I am currently stuck.
    My previous macro called by the button was previously as following:
    Please Login or Register  to view this content.
    I can't figure out how to ask it to use the value cs for the variable ccol.

    I have attached an updated file ForumTestButton_2.xlsm.
    Thank you for any help!

+ 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. Checkbox Count After Pressing Button
    By jamalfried in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2013, 12:48 PM
  2. [SOLVED] Concatenation in VBA - After pressing the Button
    By harishankarin in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 12-13-2012, 03:54 PM
  3. Pressing a button to make a new order
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-09-2011, 06:35 AM
  4. returning the activecell's page number
    By gill in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-07-2006, 03:20 AM
  5. [SOLVED] Pressing a button using a macro
    By Todd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2005, 04:05 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