Creating a health food database that pulls info based on dropdown list

Danimal713

New Member
Joined
Dec 6, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
O, so I'm creating a health food database that has all nutritional information for a variety of foods. I plan to add to this database consistently. On the first sheet, I want to be able to select from a dropdown list of foods that I am eating daily, and I would like the pertinent info to populate based on dropdown selection.

For instance: Database in another sheet looks like this
NameCaloriesTotal fatProtienFiber
Banana50332
Toast120522.5

On the first sheet, I'd like to pick either banana or toast for my daily meal from a dropdown and have the nutritional info show on that page so it can be added up for daily values.

This is probably simple for excel pros, which I am not. Thank you for any help.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You did not provide sheet names so I used the name "Facts"
Modify this word in the code if needed. This is the sheet we need to search for values.
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab where you want to enter the value to search for.
And since you did not say what column the drop down menu will be in I assumed it will be column A
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

It's best to provide specific details when looking for help.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  12/6/2020  11:15:50 PM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Column = 1 Then
On Error GoTo M
Dim ans As String
Dim lastColumn As Long
ans = Target.Value
Dim SearchString As String
Dim SearchRange As Range
SearchString = ans
Dim lastrow As Long
lastrow = Sheets("Facts").Cells(Rows.Count, "A").End(xlUp).Row
Set SearchRange = Sheets("Facts").Range("A2:A" & lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If SearchRange Is Nothing Then MsgBox SearchString & "  Not Found": Exit Sub
lastColumn = Sheets("Facts").Cells(SearchRange.Row, Columns.Count).End(xlToLeft).Column
SearchRange.Offset(, 1).Resize(, lastColumn).Copy Sheets(1).Cells(Target.Row, 2)
End If
M:
MsgBox "We had a Error"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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