Adding data to a cell depending on the value of another cell

liampog

Active Member
Joined
Aug 3, 2010
Messages
316
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

In one sheet in the workbook I have a list of customer names in A2:A1001 (Named: customer_names) with their corresponding membership numbers in B2:B1001 (Named: member_numbers).

In another sheet on the workbook I have a Data Validation (LIST) set up to create dropdown menus in the cells (example cell A2) to choose the customer name in the named range or to be able to type any customer name.

Is there any way in the adjacent cell to the Data Validation dropdown cell to be able to automatically fill the member number (example in cell B2) if a known name is chosen from the dropdown?

I think it will be a Worksheet_Change which will do a search when the customer name cell is changed (either by typing a name manually or selecting from the dropdown) and if it finds the name in the Named Range on the other sheet, it automatically changes the value of the cell to equal that of the membership number. If it doesn't find the name of the customer, it does nothing and allows the user to just manually enter a membership number.

I hope this makes sense,
Liam
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
In B2 enter
=VLOOKUP(A2,customer_group,2,FALSE)

customer_group is the named group of A2:B1001 on workbook 1
 
Upvote 0
Hi there

Although this works, because it's a formula it doesn't allow for a manually entered number to be put in by the user.

I think I need a Worksheet_Change event monitoring the A2 (customer name dropdown cell) that will search for the value in A2 in the worksheet containing the list of customer names and numbers.

If it finds it, then it changes the value of B2 to the correct membership number for the customer name.

But it should also allow for a manual entry of membership number should it NOT find the customer name in the list.

Liam
 
Upvote 0
In VBAProject /Microsoft Excel Objects/Sheet2 paste this:

Sub Worksheet_Change(ByVal Target As Range)
'
If (ActiveCell.Address = "$A$2") Then
FoundName = False
i = 0
Do While Not (FoundName) And (i <= 1001)
i = i + 1
If (Sheets("Sheet1").Cells(i, 1).Value = Range("A2").Value) Then
Range("B2").Value = Sheets("Sheet1").Cells(i, 2).Value
FoundName = True
End If
Loop
Else
Range("B2").ClearContents
End If
End Sub

It's the closest I could get for you.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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