![]() |
Programming a button
I have a button that I only want to be active if an adjacent cell on the left
is null AND the cell on the right is not null. So basically there are 8 buttons and I only want ONE to be active at a time, the LAST one that has data in it. I have NEVER programmed VBA in Excel. I am proficient in VBA in Access however. Once the button is active, I want it to copy all the values of each cell into corresponding cells in another worksheet. I truly appreciate any help you experts can provide. Larry -- Never give up, the answer IS out there, it just takes a while to find it sometimes! |
Programming a button
Right click on the worksheet tab and select view code.
Put in code like this which will fire each time the user selects a cell. Private Sub Worksheet_SelectionChange(ByVal Target As Range) For Each oObject In Me.OLEObjects If TypeOf oObject.Object Is MSForms.CommandButton Then Set rng = oObject.TopLeftCell If IsEmpty(rng.Offset(0, -1)) And IsEmpty(rng.Offset(0, 1)) Then oObject.Object.Enabled = True Else oObject.Object.Enabled = False End If End If Next End Sub this assumes commandbuttons from the control toolbox toolbar. Your description is contradictory. You say you want the button enabled if the cells are empty, but then you say you want the button enabled for the last one with data. You say when the button is made active, it should copy some data. You don't want the user to click the button. If not, then why have buttons? Perhas you can program Access with such vague descriptions, but excel requires more definition as to where things are. -- Regards, Tom Ogilvy "Larry G." wrote: I have a button that I only want to be active if an adjacent cell on the left is null AND the cell on the right is not null. So basically there are 8 buttons and I only want ONE to be active at a time, the LAST one that has data in it. I have NEVER programmed VBA in Excel. I am proficient in VBA in Access however. Once the button is active, I want it to copy all the values of each cell into corresponding cells in another worksheet. I truly appreciate any help you experts can provide. Larry -- Never give up, the answer IS out there, it just takes a while to find it sometimes! |
All times are GMT +1. The time now is 01:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com