+ Reply to Thread
Results 1 to 5 of 5

Code to an in cell drop down list

Hybrid View

  1. #1
    frendabrenda1
    Guest

    Code to an in cell drop down list

    I would like to assign code to an in cell drop down list..... so that once an
    item is chosen it would run the code. Is this possible? I know you can
    attach code to a control list box, but I am having trouble creating a
    dependant list like I can with the in cell drop down.

    Thanks for any help.

  2. #2
    Otto Moehrbach
    Guest

    Re: Code to an in cell drop down list

    You can use a Worksheet_Change event macro like:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) <> A1 Then Exit Sub
    If Target = "" Then Exit Sub
    Call YourMacro
    Application.EnableEvents = False
    Target.ClearContents
    Application.EnableEvents = True
    End Sub
    This macro will run your macro whenever the contents of A1 are changed to
    anything other than blank. This macro must be placed in the sheet module of
    your sheet. To do this, right-click on the tab of your sheet, select View
    Code, and paste this macro into that module. HTH Otto
    "frendabrenda1" <frendabrenda1@discussions.microsoft.com> wrote in message
    news:91CB28A4-52BF-4FF6-9278-63A868545309@microsoft.com...
    >I would like to assign code to an in cell drop down list..... so that once
    >an
    > item is chosen it would run the code. Is this possible? I know you can
    > attach code to a control list box, but I am having trouble creating a
    > dependant list like I can with the in cell drop down.
    >
    > Thanks for any help.




  3. #3
    frendabrenda1
    Guest

    Re: Code to an in cell drop down list

    I cannot get this code to work. I have tried writing the instructions in a
    separate macro, and also replacing the "yourmacro" with the instructions
    directly and neither runs the code upon changing A1 or any other cell I try.

    What am I doing wrong?????

    "Otto Moehrbach" wrote:

    > You can use a Worksheet_Change event macro like:
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Target.Address(0, 0) <> A1 Then Exit Sub
    > If Target = "" Then Exit Sub
    > Call YourMacro
    > Application.EnableEvents = False
    > Target.ClearContents
    > Application.EnableEvents = True
    > End Sub
    > This macro will run your macro whenever the contents of A1 are changed to
    > anything other than blank. This macro must be placed in the sheet module of
    > your sheet. To do this, right-click on the tab of your sheet, select View
    > Code, and paste this macro into that module. HTH Otto
    > "frendabrenda1" <frendabrenda1@discussions.microsoft.com> wrote in message
    > news:91CB28A4-52BF-4FF6-9278-63A868545309@microsoft.com...
    > >I would like to assign code to an in cell drop down list..... so that once
    > >an
    > > item is chosen it would run the code. Is this possible? I know you can
    > > attach code to a control list box, but I am having trouble creating a
    > > dependant list like I can with the in cell drop down.
    > >
    > > Thanks for any help.

    >
    >
    >


  4. #4
    Dave Peterson
    Guest

    Re: Code to an in cell drop down list

    This code goes behind the worksheet that has the dropdown (you built the
    dropdown via data|validation, didn't you???).

    Right click on the worksheet tab, select view code and paste Otto's code there.

    (change YourMacro to the correct name, too.)



    frendabrenda1 wrote:
    >
    > I cannot get this code to work. I have tried writing the instructions in a
    > separate macro, and also replacing the "yourmacro" with the instructions
    > directly and neither runs the code upon changing A1 or any other cell I try.
    >
    > What am I doing wrong?????
    >
    > "Otto Moehrbach" wrote:
    >
    > > You can use a Worksheet_Change event macro like:
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > If Target.Address(0, 0) <> A1 Then Exit Sub
    > > If Target = "" Then Exit Sub
    > > Call YourMacro
    > > Application.EnableEvents = False
    > > Target.ClearContents
    > > Application.EnableEvents = True
    > > End Sub
    > > This macro will run your macro whenever the contents of A1 are changed to
    > > anything other than blank. This macro must be placed in the sheet module of
    > > your sheet. To do this, right-click on the tab of your sheet, select View
    > > Code, and paste this macro into that module. HTH Otto
    > > "frendabrenda1" <frendabrenda1@discussions.microsoft.com> wrote in message
    > > news:91CB28A4-52BF-4FF6-9278-63A868545309@microsoft.com...
    > > >I would like to assign code to an in cell drop down list..... so that once
    > > >an
    > > > item is chosen it would run the code. Is this possible? I know you can
    > > > attach code to a control list box, but I am having trouble creating a
    > > > dependant list like I can with the in cell drop down.
    > > >
    > > > Thanks for any help.

    > >
    > >
    > >


    --

    Dave Peterson

  5. #5
    Dave Peterson
    Guest

    Re: Code to an in cell drop down list

    Just to add to Otto's response.

    There's a bug in xl97 that stops the worksheet_change event from firing under
    certain conditions:

    From Debra Dalgleish's site:
    http://contextures.com/xlDataVal08.html#Change

    In Excel 97, selecting an item from a Data Validation dropdown list does not
    trigger a Change event, unless the list items have been typed in the Data
    Validation dialog box.

    She also has some workarounds for this bug.



    Otto Moehrbach wrote:
    >
    > You can use a Worksheet_Change event macro like:
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Target.Address(0, 0) <> A1 Then Exit Sub
    > If Target = "" Then Exit Sub
    > Call YourMacro
    > Application.EnableEvents = False
    > Target.ClearContents
    > Application.EnableEvents = True
    > End Sub
    > This macro will run your macro whenever the contents of A1 are changed to
    > anything other than blank. This macro must be placed in the sheet module of
    > your sheet. To do this, right-click on the tab of your sheet, select View
    > Code, and paste this macro into that module. HTH Otto
    > "frendabrenda1" <frendabrenda1@discussions.microsoft.com> wrote in message
    > news:91CB28A4-52BF-4FF6-9278-63A868545309@microsoft.com...
    > >I would like to assign code to an in cell drop down list..... so that once
    > >an
    > > item is chosen it would run the code. Is this possible? I know you can
    > > attach code to a control list box, but I am having trouble creating a
    > > dependant list like I can with the in cell drop down.
    > >
    > > Thanks for any help.


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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