Link to home
Start Free TrialLog in
Avatar of JCJG
JCJG

asked on

Excel 2007 cell value of drop-down list change with formula

Hi, I have a cell with a drop-down list.  Is it possible to automatically change that cell value to one of the values from the drop-down base on the value of another cell?

For example, the drop-down list is in cell D2 with value A, B, C.  I'd like to input a value cell A2 and have D2 automatically updated with the cell in A2 but at the same time preserve the drop-down list for future changes.
Drop-down-list-change-value.xlsx
Avatar of dlmille
dlmille
Flag of United States of America image

Yes.  Here's a worksheet_change event in Sheet1's codepage that will check for changes in A2, and if there is, it will make D2 that value, still preserving the data validation list for future changes.  However, you'd need additional code to ensure the change was within the data validation rules.  What you have now, just forces the change.

Here's the code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A2")) Is Nothing Then 'a change was made in A2
        Range("D2").Value = Target.Value
    End If
    
End Sub

Open in new window


See attached demo workbook.

Enjoy!

Dave
Drop-down-list-change-value-r1.xlsm
Avatar of JCJG
JCJG

ASKER

Thanks!  The only thing is that the cell A2 is in a different worksheet.  I have linked value to the target worksheet but the value of the target cell won't change unless I clicked on the linked cell and hit enter.  How to fix this?
Is the different worksheet online at the same time, or is it closed and stored on a server somewhere?  You really need to describe your environment more, so I can help you further.  Please be much more explicit with what is going on, to avoid rework.

Thanks,

Dave
Avatar of JCJG

ASKER

All the worksheets are contained in the same workbook so they are online at the same time.  Thanks.
Ok - what is the name of the worksheet that has the code you're trying to put in the data validation dropdown - and what is the range of the cell in that worksheet?  We just need to modify the code to affect the change...

E.g., let's assume Sheet1, Range C2 is where you're making data changes - but you want the result of Range C2 in Sheet2 to go to that data validation dropdown cell.

If I've described all that right, just let me know the details, or upload a simple mock spreadsheet to that effect.

Dave
Avatar of JCJG

ASKER

Yes, your description is correct.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JCJG

ASKER

Thanks!  This is what I need.  I apologize for the late reply.