Excel formula or VBA to paste list of data from reference worksheet if specific text is selected in data worksheet

Lisa Harris

New Member
Joined
Sep 19, 2016
Messages
17
Hi, hoping someone can help as I cannot find a solution at all.

I have a workbook with two sheets. One is the active data sheet (sheet 1), the other is a reference / list (sheet 2).

Sheet 2 details across the columns (C:E) the 'Types', and below each type, lists the Tasks for that type (used letters for this example):


123
aaa
bbc
ccd
dd
e

<tbody>
</tbody>

<tbody>
</tbody>



Sheet 1 is the data entry sheet. In column F, a 'type' will be selected from a drop down list. When this happens, I need the relevant list for that type on sheet 2, to be pasted in column H on the row of the 'Type' and subsequent rows needed to fit the list. Once this has been done, I would also like the Type cell (column F) to be merged and centered to reach the number of rows the list is, and the same for the title (column G) - please see below (unable to show the merged cells as it sent my table all off - apologies)



columnFGHIJ
TypeTitleTasks
1title 1a
b
c
d
e
2title 2a
b
c
d
3title 3a
c
d
1title 4a
b
c
d
e
1title 5a
b
c
d
e

<tbody>
</tbody>


Many thanks in advance for any help you can offer

Lisa
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Sorry... misposted
 
Last edited:
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet1 and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. First insert the title in column G and then make a selection in column F.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim foundVal As Range
    Set foundVal = Sheets("Sheet2").Range("C1:E1").Find(Target, LookIn:=xlValues, lookat:=xlWhole)
    If Not foundVal Is Nothing Then
        Sheets("Sheet2").Range(Sheets("Sheet2").Cells(2, foundVal.Column), Sheets("Sheet2").Cells(6, foundVal.Column)).Copy _
            Cells(Rows.Count, "H").End(xlUp).Offset(1, 0)
        With Range("F" & Target.Row & ":F" & ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .MergeCells = True
        End With
        With Range("G" & Target.Row & ":G" & ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .MergeCells = True
        End With
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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