Challenging; Creating an automatic list depending on two tables...

lost_my_SQL

New Member
Joined
May 3, 2019
Messages
1
If I have a list of job titles [JBTBL], and a list of contract years [POPTBL]; I need to copy the list of job titles for as many times as I have years, lets call this the DetailTable. Then if I change/delete/add a job title from the job title table or add or delete a contract year from the POPTBL, i need the DetailTable to automatically reflect to these changes. This would save me hours of copy and pasting and re-working formulas.

**I refer to them as tables because they contain a lot more information but those are easy vlookups after i get the duplication figured out.

Hopefully my explanation makes sense.

JBTBL
PLUMBER
CARPENTER

<tbody>
</tbody>

POPTBL
YEAR 1
YEAR 2

<tbody>
</tbody>

Auto-Details Table
POPJOB
YEAR 1PLUMBER
YEAR 1CARPENTER
YEAR 2PLUMBER
YEAR 2CARPENTER

<tbody>
</tbody>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I used this layout you will need to adjust the code to match yours.

Book1
ABCDEF
1JBTBLPOPTBLPOPJob
2PLUMBERYEAR 1YEAR 1PLUMBER
3CARPENTERYEAR 2YEAR 1CARPENTER
4YEAR 2PLUMBER
5YEAR 2CARPENTER
Sheet1


Try
Code:
Sub pop()
Dim lrj As Long
Dim lry As Long
Dim lr As Long
Dim jcount As Long
Dim ycount As Long

lrj = Cells(Rows.Count, "A").End(xlUp).Row 'change to column with your JBTBL
lry = Cells(Rows.Count, "C").End(xlUp).Row 'change to column with your POPTBL
lre = Cells(Rows.Count, "E").End(xlUp).Row 'change to column with your created table is
lrf = Cells(Rows.Count, "F").End(xlUp).Row 'change to column with your created table is
jcount = lrj - 1 'assuming headers are in row 1 if not change the 1 to where the headers are
ycount = lry - 1 'assuming headers are in row 1 if not change the 1 to where the headers are
'clear table if populated
If lrf > 1 Then
    Range("E2:F" & lrf).ClearContents
    lre = Cells(Rows.Count, "E").End(xlUp).Row 'change to column with your created table is
    lrf = Cells(Rows.Count, "F").End(xlUp).Row 'change to column with your created table is
End If
For c = 1 To ycount
    Range("A2:A" & lrj).Copy Range("F" & lrf + 1)
    lrf = Cells(Rows.Count, "F").End(xlUp).Row 'change to column with your created table is
Next c
For x = 2 To lry
    For p = 1 To jcount
        Range("C" & x).Copy Range("E" & lre + 1)
        lre = Cells(Rows.Count, "E").End(xlUp).Row 'change to column with your created table is
    Next p
Next x

End Sub

If you want this could be changed to a change event so it runs automatically.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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