Add new button in row of an excel table and assign a macro

  • Hi, I have an excel table with 16 columns. I want to add another one and in the 17th I want to put a button named "edit" and assign to it the macro "macro1". To write in the excel table I use this code:



    So every time I write a new row to the excel table I add even a button. Is there a way?


    Thanks

  • Re: Add new button in row of an excel table and assign a macro


    Don't add a button in every row... Add one (Forms, not ActiveX) button, name it 'btnEdit' (or change the code to suit), assign your macro to it and paste the following in the worksheet class module...



    The button will move to Column 17 of whichever row is selected and sized to fit the cell. If a row number greater then the count of rows in the UsedRange is selected then the button will be hidden.

  • Re: Add new button in row of an excel table and assign a macro


    Thanks for the help cytop... I've tryed and it works, but not as I wish. The button don't fit completely the cell (it's a little on the left) and moreover it's not always visible. I'm not an expert one in vba, but there is not a way to just use the .offset (rowcount, 18) to put the button in this cell (everytime I add a new row to the excel table? Or to make it always visible?

  • Re: Add new button in row of an excel table and assign a macro


    Quote

    ...The button don't fit completely


    Can't see how - the button is sized to the cell using the cell co-ordinates and measurements. Also can't see how it's not always visible. As long as the row is less then the number of used rows in the range then it will be visible and it uses the same calculation you originally quoted to find the number of rows - so other parts of your code should be displaying the same issue. If you simply added a button to every row, you (presumably) would have the same sizing problem.


    Post a sample workbook that displays these issues.


    Please do not quote entire posts in your reply - if anyone wants to read them they can simply scroll up a little...

  • Re: Add new button in row of an excel table and assign a macro


    The banded table formatting draws some odd borders, bu tI didn't think it was that noticable. In any case, the 'Modify' column should not really be part of the table - you should change the table definition.


    The button name was "Button 7" - you were referring to it as "Pulsante 7", which is understandable I suppose, but the code needs to refer to "Button 7", or whatever you rename it to.


    You can rename the button (don't confuse the Name with the Caption) by clicking on Design Mode on the Developer tab, then clicking once on the button ans changing the name in the 'Name' box which is displayed to the left of the Formula Box, just under the Ribbon.


    The code below has been modified so the button will only be displayed when the cursor in actually in the data table. This has the slightly unfortunate effect of making the button disappear if the user moves the cursor to column R, but preferable, in my opinion, to having one button per row.



    If you really, must have one button per row, then change the Procedure cmdIscrivi_Click on the userform to include the following code block


    (You will need to change all references to Col 18 to 17 to agree with your initial request).

  • Re: Add new button in row of an excel table and assign a macro


    Ok, it works great now, but you make me think. Is there a way to show the edit button just in the selected row next to where I click? It's just an idea, maybe it's impossible, but I want to ask. Anyway Thank a lot! :)

  • Re: Add new button in row of an excel table and assign a macro


    MODERATOR NOTICE: This topic has also been posted on other sites and may already have an answer elsewhere. Please take this into consideration when answering this question

    *

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!