VB to repeat range and create list for each user

JV0710

Active Member
Joined
Oct 26, 2006
Messages
429
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Good Day
Please can I get some help with a macro for the below

I have a sheet with Range A1 : Z16 with Row 1 being headings. The header for column A is “User Name”, column B is “Task” and the balance of the columns relate to various dates and Values and comments .
There are 15 tasks therefore 15 rows Plus 1 for headers.

I have a separate list of 20 users Names

I would like a macro to create list of the 15 Rows for each of the 20 users with each set having a user name from the separate list

Thanks in advance for your help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
you would need to show your data, preferably in an XL2BB. Both the original data and what you would like the data to look like when it's finished.
 
Upvote 0
Hi Dermie

Below is the table I have on Sheet1

User NameTaskLocationAreaBrandGroupCategoryCheck DateStatusCurrencyCostUnitsMinimumMaximumNext CheckVendorScheduleTimingColour CodeCommentSpecial InstrExtra 1Extra 2Extra 3Extra 4Extra 5
Task 1Location 1Area1Brand aGrp1Cat10
Task 1Location 2Area1Brand aGrp2Cat10
Task 1Location 3Area1Brand aGrp3Cat10
Task 1Location 4Area1Brand aGrp4Cat10
Task 1Location 5Area1Brand aGrp5Cat10
Task 2Location 1Area2Brand bGrp1Cat20
Task 2Location 2Area2Brand bGrp2Cat20
Task 2Location 3Area2Brand bGrp3Cat20
Task 2Location 4Area2Brand bGrp4Cat20
Task 2Location 5Area2Brand bGrp5Cat20
Task 3Location 1Area3Brand cGrp1Cat30
Task 3Location 2Area3Brand cGrp2Cat30
Task 3Location 3Area3Brand cGrp3Cat30
Task 3Location 4Area3Brand cGrp4Cat30
Task 3Location 5Area3Brand cGrp5Cat30



Below is the list of User Names I have on Sheet2

User Names
Mary
Jane
Bob
Joe
John
Patrick
Darryll
Lance
Carol
Frank
James
Moe
Audria
Craig
Estelle
Cary
Noel
Sue
Calvin


Below is the result I would like the Macro to produce

User NameTaskLocationAreaBrandGroupCategoryCheck DateStatusCurrencyCostUnitsMinimumMaximumNext CheckVendorScheduleTimingColour CodeCommentSpecial InstrExtra 1Extra 2Extra 3Extra 4Extra 5
MaryTask 1Location 1Area1Brand aGrp1Cat10
MaryTask 1Location 2Area1Brand aGrp2Cat10
MaryTask 1Location 3Area1Brand aGrp3Cat10
MaryTask 1Location 4Area1Brand aGrp4Cat10
MaryTask 1Location 5Area1Brand aGrp5Cat10
MaryTask 2Location 1Area2Brand bGrp1Cat20
MaryTask 2Location 2Area2Brand bGrp2Cat20
MaryTask 2Location 3Area2Brand bGrp3Cat20
MaryTask 2Location 4Area2Brand bGrp4Cat20
MaryTask 2Location 5Area2Brand bGrp5Cat20
MaryTask 3Location 1Area3Brand cGrp1Cat30
MaryTask 3Location 2Area3Brand cGrp2Cat30
MaryTask 3Location 3Area3Brand cGrp3Cat30
MaryTask 3Location 4Area3Brand cGrp4Cat30
MaryTask 3cLocation 5Area3Brand cGrp5Cat30
JaneTask 1Location 1Area1Brand aGrp1Cat10
JaneTask 1Location 2Area1Brand aGrp2Cat10
JaneTask 1Location 3Area1Brand aGrp3Cat10
JaneTask 1Location 4Area1Brand aGrp4Cat10
JaneTask 1Location 5Area1Brand aGrp5Cat10
JaneTask 2Location 1Area2Brand bGrp1Cat20
JaneTask 2Location 2Area2Brand bGrp2Cat20
JaneTask 2Location 3Area2Brand bGrp3Cat20
JaneTask 2Location 4Area2Brand bGrp4Cat20
JaneTask 2Location 5Area2Brand bGrp5Cat20
JaneTask 3Location 1Area3Brand cGrp1Cat30
JaneTask 3Location 2Area3Brand cGrp2Cat30
JaneTask 3Location 3Area3Brand cGrp3Cat30
JaneTask 3Location 4Area3Brand cGrp4Cat30
JaneTask 3cLocation 5Area3Brand cGrp5Cat30
BobTask 1Location 1Area1Brand aGrp1Cat10
BobTask 1Location 2Area1Brand aGrp2Cat10
BobTask 1Location 3Area1Brand aGrp3Cat10
BobTask 1Location 4Area1Brand aGrp4Cat10
BobTask 1Location 5Area1Brand aGrp5Cat10
BobTask 2Location 1Area2Brand bGrp1Cat20
BobTask 2Location 2Area2Brand bGrp2Cat20
BobTask 2Location 3Area2Brand bGrp3Cat20
BobTask 2Location 4Area2Brand bGrp4Cat20
BobTask 2Location 5Area2Brand bGrp5Cat20
BobTask 3Location 1Area3Brand cGrp1Cat30
BobTask 3Location 2Area3Brand cGrp2Cat30
BobTask 3Location 3Area3Brand cGrp3Cat30
BobTask 3Location 4Area3Brand cGrp4Cat30
BobTask 3cLocation 5Area3Brand cGrp5Cat30
JoeTask 1Location 1Area1Brand aGrp1Cat10
JoeTask 1Location 2Area1Brand aGrp2Cat10
JoeTask 1Location 3Area1Brand aGrp3Cat10
JoeTask 1Location 4Area1Brand aGrp4Cat10
JoeTask 1Location 5Area1Brand aGrp5Cat10
JoeTask 2Location 1Area2Brand bGrp1Cat20
JoeTask 2Location 2Area2Brand bGrp2Cat20
JoeTask 2Location 3Area2Brand bGrp3Cat20
JoeTask 2Location 4Area2Brand bGrp4Cat20
JoeTask 2Location 5Area2Brand bGrp5Cat20
JoeTask 3Location 1Area3Brand cGrp1Cat30
JoeTask 3Location 2Area3Brand cGrp2Cat30
JoeTask 3Location 3Area3Brand cGrp3Cat30
JoeTask 3Location 4Area3Brand cGrp4Cat30
JoeTask 3cLocation 5Area3Brand cGrp5Cat30
JohnTask 1Location 1Area1Brand aGrp1Cat10
JohnTask 1Location 2Area1Brand aGrp2Cat10
JohnTask 1Location 3Area1Brand aGrp3Cat10
JohnTask 1Location 4Area1Brand aGrp4Cat10
JohnTask 1Location 5Area1Brand aGrp5Cat10
JohnTask 2Location 1Area2Brand bGrp1Cat20
JohnTask 2Location 2Area2Brand bGrp2Cat20
JohnTask 2Location 3Area2Brand bGrp3Cat20
JohnTask 2Location 4Area2Brand bGrp4Cat20
JohnTask 2Location 5Area2Brand bGrp5Cat20
JohnTask 3Location 1Area3Brand cGrp1Cat30
JohnTask 3Location 2Area3Brand cGrp2Cat30
JohnTask 3Location 3Area3Brand cGrp3Cat30
JohnTask 3Location 4Area3Brand cGrp4Cat30
JohnTask 3cLocation 5Area3Brand cGrp5Cat30
 
Upvote 0
Sheet1 --> Tasks
sheet2 --> User names
Sheet3 is Macro result.
Code
VBA Code:
Sub UserName_Task()
Dim Tsk As Range, A, T&, Ros&
Application.ScreenUpdating = False
With Sheets("Sheet1").Range("A1").CurrentRegion
Set Tsk = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
Ros = .Rows.Count - 1
End With

A = Sheets("Sheet2").Range("A1").CurrentRegion
With Sheets("Sheet3")
.Range("A1").CurrentRegion.Clear
Sheets("Sheet1").Range("1:1").Copy .Range("A1")
For T = 2 To UBound(A, 1)
Tsk.Copy .Range("A" & 2 + (T - 2) * Ros)            '.Cells(1, (T - 2) * Ros)
.Range("A" & 2 + (T - 2) * Ros).Resize(Ros, 1) = A(T, 1)
Next T
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Sheet1 --> Tasks
sheet2 --> User names
Sheet3 is Macro result.
Code
VBA Code:
Sub UserName_Task()
Dim Tsk As Range, A, T&, Ros&
Application.ScreenUpdating = False
With Sheets("Sheet1").Range("A1").CurrentRegion
Set Tsk = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
Ros = .Rows.Count - 1
End With

A = Sheets("Sheet2").Range("A1").CurrentRegion
With Sheets("Sheet3")
.Range("A1").CurrentRegion.Clear
Sheets("Sheet1").Range("1:1").Copy .Range("A1")
For T = 2 To UBound(A, 1)
Tsk.Copy .Range("A" & 2 + (T - 2) * Ros)            '.Cells(1, (T - 2) * Ros)
.Range("A" & 2 + (T - 2) * Ros).Resize(Ros, 1) = A(T, 1)
Next T
End With
Application.ScreenUpdating = True
End Sub
Thanks very much sir . . . That is exactly what was required
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,050
Members
449,092
Latest member
ikke

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