Populate a range based on the selection in one cell

STCrosstown

New Member
Joined
Aug 24, 2018
Messages
9
So I am trying get a range to populate based on the selection in a single cell. So in the pic below, i have two types of projects. Admine Projects and IT Projects. They have different cost categories listed in column A and B. Cell D2 is a data validation where you can select either "Admine Projects, or IT_Project". I want the range F2:F13 to populate with the categories for the respective projects based on the selection in cell D2.

So when I select "Admine Projects" in cell D2 I would like the range F2:F13 to populate with the information in the range A2:A13.

How can i do this?

hYWtmi9.png
[/URL][/IMG]
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe this formula copied down

Code:
=IF($D$2="Admin Projects",A2,B2)

or a code

Code:
Sub MM1()
Select Case Range("D2").Value
    Case Is = "Admin Projects"
        Range("A2:A13").Copy Range("F2")
    Case Else
         Range("B2:B13").Copy Range("F2")
   End Select
End Sub
 
Last edited:
Upvote 0
Thanks Michael M, the code is working and i have it set up to ref 7 named ranges.

Follow up question, If i move the button that activates the macro to a different sheet it no longer works. How do i imbed worksheet designation as well?

Thanks much
 
Upvote 0
That's becasue it is trying to run on the sheet where the button resides.
To make it work for a different sheet you must refer back to that sheet
change the text in RED to the sheet name you want the code to refer to
Code:
Sub MM1()
dim ws as worksheet
set ws = Sheets("[color=red]sheet1[/color]")
with ws
 Select Case .Range("D2").Value
    Case Is = "Admin Projects"
        .Range("A2:A13").Copy .Range("F2")
    Case Else
         .Range("B2:B13").Copy .Range("F2")
   End Select
end with
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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