ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Challenge of the day: linking VBA code to combo box selections (https://www.excelbanter.com/excel-programming/370812-challenge-day-linking-vba-code-combo-box-selections.html)

Todd in Dayton

Challenge of the day: linking VBA code to combo box selections
 
I have created a combo box by selecting a cell and using Data<Validation<List
and selecting values on a different worksheet.

I would like for when a user selects a value from the combobox, for a VBA
function to run (to change certain cell properties).

Is this possible???

Thank you very much.

Les

Challenge of the day: linking VBA code to combo box selections
 
Assuming your combobox is in cell G2, in the worksheet code try something like:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$2" Then
Range("G5") = Target.Value 'do something with value
End If
End Sub
--
Les Torchia-Wells


"Todd in Dayton" wrote:

I have created a combo box by selecting a cell and using Data<Validation<List
and selecting values on a different worksheet.

I would like for when a user selects a value from the combobox, for a VBA
function to run (to change certain cell properties).

Is this possible???

Thank you very much.


Tom Ogilvy

Challenge of the day: linking VBA code to combo box selections
 
Right click on the sheet tab of the sheet with the dropdown datavalidation
and select view code. Put in code like this

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler
If Target.Address = "$B$9" Then
Application.EnableEvents = False
Call MyMacro
End If
ErrHandler:
Application.EnableEvents = True
End Sub

As written, this reacts to changes in cell B9. The code you want to run
should be in a subroutine in a general module in the workbook and have the
name mymacro (of course that can be changed as can the cell reference).

Note that this will not work in xl97 and earlier.

--
Regards,
Tom Ogilvy


"Todd in Dayton" wrote:

I have created a combo box by selecting a cell and using Data<Validation<List
and selecting values on a different worksheet.

I would like for when a user selects a value from the combobox, for a VBA
function to run (to change certain cell properties).

Is this possible???

Thank you very much.



All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com