VBA to select range from another sheet on drop down selection

Bamh1

New Member
Joined
Oct 7, 2021
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
Hello,

I have a master sheet that contains combinations of activity types for 3 business units, and Infront of each combination there is a row of information.

In another sheet, I have created drop down menus for the activity types (Col. A), and business units(Col. B). Upon selection of the drop down in column B, I want the corresponding row of information (range c:g) for that particular combination copied from the master sheet in front of the selection.

Could someone please help with a VBA or if there is another way to do this non programmatically.

Thank you.

Shawn
 

Attachments

  • Master Sheet Combinations-1.PNG
    Master Sheet Combinations-1.PNG
    15.4 KB · Views: 5
  • 1663357008551_1663356943455_Drop down selection generating fields.PNG
    1663357008551_1663356943455_Drop down selection generating fields.PNG
    6.5 KB · Views: 7

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You should have XLOOKUP() with 2016, so the following will avoid the need for VBA. Assumes your table of data is on Sheet1 (change to suit).

Book1
ABCDEFG
1Activity TypeBusiness UnitField1Field2Field3Field4Field5
2Activity2Unit2AU221AU221AU221AU221AU221
3
Sheet2
Cell Formulas
RangeFormula
C2:G2C2=XLOOKUP($A$2&$B$2,Sheet1!$A$2:$A$10&Sheet1!$B$2:$B$10,Sheet1!C2:C10,"")
Cells with Data Validation
CellAllowCriteria
A2List=$I$1:$I$3
B2List=$J$1:$J$3
 
Upvote 0
The data set I used in post #2 wasn't a true reflection of yours, so here's another look.

Data set (Master sheet)
xlookup.xlsx
ABCDEFG
1Activity TypeBusiness UnitField1Field2Field3Field4Field5
2Activity1Unit1AU111AU112AU113AU114AU115
3Activity2Unit1AU211AU212AU213AU214AU215
4Activity3Unit1AU311AU312AU313AU314AU315
5Activity1Unit2AU121AU122AU123AU124AU125
6Activity2Unit2AU221AU222AU223AU224AU225
7Activity3Unit2AU321AU322AU323AU324AU325
8Activity1Unit3AU131AU132AU133AU134AU135
9Activity2Unit3AU231AU232AU233AU234AU235
10Activity3Unit3AU331AU332AU333AU334AU335
Sheet1


Result
xlookup.xlsx
ABCDEFG
1Activity TypeBusiness UnitField1Field2Field3Field4Field5
2Activity2Unit2AU221AU222AU223AU224AU225
3
Sheet2
Cell Formulas
RangeFormula
C2:G2C2=XLOOKUP($A$2&$B$2,Sheet1!$A$2:$A$10&Sheet1!$B$2:$B$10,Sheet1!C2:C10,"")
Cells with Data Validation
CellAllowCriteria
A2List=$I$1:$I$3
B2List=$J$1:$J$3
 
Upvote 0
The data set I used in post #2 wasn't a true reflection of yours, so here's another look.

Data set (Master sheet)
xlookup.xlsx
ABCDEFG
1Activity TypeBusiness UnitField1Field2Field3Field4Field5
2Activity1Unit1AU111AU112AU113AU114AU115
3Activity2Unit1AU211AU212AU213AU214AU215
4Activity3Unit1AU311AU312AU313AU314AU315
5Activity1Unit2AU121AU122AU123AU124AU125
6Activity2Unit2AU221AU222AU223AU224AU225
7Activity3Unit2AU321AU322AU323AU324AU325
8Activity1Unit3AU131AU132AU133AU134AU135
9Activity2Unit3AU231AU232AU233AU234AU235
10Activity3Unit3AU331AU332AU333AU334AU335
Sheet1


Result
xlookup.xlsx
ABCDEFG
1Activity TypeBusiness UnitField1Field2Field3Field4Field5
2Activity2Unit2AU221AU222AU223AU224AU225
3
Sheet2
Cell Formulas
RangeFormula
C2:G2C2=XLOOKUP($A$2&$B$2,Sheet1!$A$2:$A$10&Sheet1!$B$2:$B$10,Sheet1!C2:C10,"")
Cells with Data Validation
CellAllowCriteria
A2List=$I$1:$I$3
B2List=$J$1:$J$3
Thank you so much for taking the time to review this post. Your solution works.
 
Upvote 0
In that case what version of Excel are you using? 2016 does not have the XLOOKUP function.
I do have access to excel365, and tested out the xlookup solution; however, I eventually need a VBA solution because: 1) xlookup only finds cell values and not formatting, and the reference cells are color-coded; 2) xlookup solution limits transferability of the file to the machines that don't have the latest excel version. Do you know a VBA code that could help in this situation?
Thanks
 
Upvote 0
I eventually need a VBA solution because: 1) xlookup only finds cell values and not formatting, and the reference cells are color-coded
This is the sort of thing that you should have mentioned originally. ;)
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

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