dropdown with vlookup by vba

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,430
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i have data sheet1 in b2 and c2 the brand and the price and result in sheet1 bring data when choose by dropdown from b2:b based on b2 in sheet2 then bring price from sheet2 c2 to col c multiple col a into sheet1 by the way i have data about 1000rows so if do that by vba is better
sheet2
18.xlsm
BC
1brandprice
2aa2000
sheet2


result in sheet1 when choose from dropdown
18.xlsm
ABC
1qbrandprice
2٢aa4000
32aa
43aa
sheet1
Cell Formulas
RangeFormula
C2C2=VLOOKUP(B2,sheet2!B2:C13,2,0)*A2
Cells with Data Validation
CellAllowCriteria
B2:B4List=OFFSET(sheet2!$B$2;;;COUNTA(sheet2!B:B)-1)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Not sure what you're trying to do really...

VBA Code:
For i = 2 to last Row
   If thisworkbook.worksheets("YoSheet").cells(i,     whateverYourColumnIs) = thisworkbook...Cells(2,2) then
    Price cell = thisworkbook...cells(i, PriceColumn)
    Exit For
Next i
 
Upvote 0
hi, richh as you see in sheet1 when choose dropdown in col b it supposes bring price from sheet2 in col c multiple quantity in col a
 
Upvote 0
Ah ok I see. You may want to use .Target.Offset(0, 1 or -1) rather than static references as i have below. You'll also want to make the function be an after_update on Sheet1 and wrap the code in an If statement that checks to see if the target was in column B something like

If target.column = 2 then...

I can't remember the syntax off the top of my head. Sorry

VBA Code:
For I = 2 to lastRow
    If thisworkbook.worksheets("Sheet2").cells(i,1) = thisworkbook.worksheets("Sheet1").cells(2,2) then
        Thisworkbook.worksheets("Sheet1").cells(2,3) = "=A1*" & thisworkbook.worksheets("Sheet2").cells(i,2)
        Exit For
    End If
Next i
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,773
Messages
6,126,820
Members
449,340
Latest member
hpm23

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