Results 1 to 3 of 3

Thread: [RESOLVED] Excel VBA: Attach a macro to a picklist?

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Resolved [RESOLVED] Excel VBA: Attach a macro to a picklist?

    hey yers.

    I have a picklist, which i am gathering from a named range, using the data validation -> list = named range ETC.

    now, i am guessing it prolly wont b possible, but im still hoping to give it a shot:

    can i assign a macro to run every time this list item changes?

    when the list changes, i wish to fetch some data from another sheet, to re-populate my sheet (this i know how to do), but i dont know how to initiate the macro when it changes.

    would i need to use the combobox of the forms? or is it possible from the normal drop down?.

    if i need to use the combobox it isnt too much of a bother, EXCEPT: how do i refer to a combo box item that is selected via the VBA ide in the code?.... (so i can place the value in a cell, and not just the list index (which the LINK TO CELL option does) so i can easily use it in all the formulae in my workbook ETC...

    it would be alot more helpful if i didnt have to use the combo box tho..... ne one wanna help me wid dis?

    Tnx.
    Wayne

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    In the IDE, in the Project Explorer pane, under your VBA Project, under Microsoft Excel Objects, double-click on the Sheet that has the cell wth the validation. This opens the Worksheet module. In the drop-down at the top of the module, change (General) to Worksheet. In the drop-down next to it, select the Change event. This fires whenever the workbook is changed. The Change event passes a Target range that represents the cell (or range of cells) that was changed. For example, if your validation is in cell D6:

    In a worksheet:

    VB Code:
    1. Private Sub Worksheet_Change(ByVal Target As Range)
    2.     If Target.Address = "$D$6" Then
    3.         MsgBox "You changed cell D6 to " & Target.Value
    4.     End If
    5. End Sub

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    cool.

    thanks, thats got it - just gotta fill in ma code to fetch the new data when thats changed and im "done" with the coding (for now)

    Taa.
    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width