VBA using dropdown to select another cell value

dknipe

New Member
Joined
Jan 18, 2018
Messages
13
Ok pulling my hair out here-
trying to get the value from column B in sheet2, by selecting dropdown list from column A

I have a dropdown list in sheet1 column J taking values from sheet2 column A
I created a defined name for column A and column B in sheet2 "my_defined_name"

I added VBA code to sheet1:

Private Sub Dropdown_Change(ByVal Target As Range)
selectedVal = Target.Value


If Target.Column = 10 Then
selectedNum = Application.VLookup(selectedVal, Worksheets("Sheet2").Range("my_defined_name"), 2, False)


If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If


End If
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your Sheet1 and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column J.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("J:J")) Is Nothing Then Exit Sub
    Dim foundVal As Range
    Set foundVal = Sheets("Sheet2").Range("A:A").Find(Target, LookIn:=xlValues, lookat:=xlWhole)
    If Not foundVal Is Nothing Then
        Target = foundVal.Offset(0, 1)
    End If
End Sub
 
Last edited:
Upvote 0
thanks for help

still not working tho - I am using Mac, but can't see anywhere that this would be factor here
 
Upvote 0
My understanding of what you want to do is to find the value selected in the drop down list from Sheet1 in column A of Sheet2 and return the value in column B to the right of the found value. Then replace the value selected in the drop down list with the value form column B. If this is not correct, please clarify in detail. This works on a PC but I have no experience on a Mac.
 
Last edited:
Upvote 0
yes you are correct, but for some reason not working on my Mac. I guess it must be a Mac thing. cheers
 
Upvote 0

Forum statistics

Threads
1,215,410
Messages
6,124,755
Members
449,187
Latest member
hermansoa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top