VBA Transpose & Join Help

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
223
Office Version
  1. 365
  2. 2019
  3. 2010
Platform
  1. Windows
Data is being pulled from SHEET2 and transposed and joined on SHEET1.
Problem:
  • It is not pulling all the data on SHEET1 because Column D Person has too many items.
  • There are 12 persons and it is not pulling for all 12 people.
  • It seems to only pull up to 11 items maximum per Person instead of the full count of 30+ rows.

VBA Code:
VBA Code:
Sub ReArrange()

Dim a As Variant, b As Variant, cr As Variant

Dim d As Object

Dim i As Long, lr As Long

 

Set d = CreateObject("Scripting.Dictionary")

d.CompareMode = 1

With Sheets("Sheet2")

lr = .Range("B" & Rows.Count).End(xlUp).Row

a = Application.Index(.Cells, Evaluate("row(2:" & lr & ")"), Array(5,2,4,3))
End With

ReDim b(1 To UBound(a), 1 To UBound(a))

For i = 1 To UBound(a)

If Not d.exists(a(i, 3)) Then d(a(i, 3)) = d.Count + 1 & " 1"

    cr = Split(d(a(i, 3)))

    b(cr(1), cr(0)) = Join(Application.Index(a, i, Array(2, 3, 4)), vbLf)

    d(a(i, 3)) = cr(0) & " " & cr(1) + 1

 

  Next i

  With Sheets("Sheet2")

    With .Range("A2").Resize(UBound(a), d.Count)

      .WrapText = True

      .Value = b

      .Rows(0).Value = d.Keys
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do you want to provide some sample data (preferably as an xl2bb) and expected results ?
Dimensioning b as a square (rows & columns equal) would seem to be a red flag.
 
Upvote 0
Do you want to provide some sample data (preferably as an xl2bb) and expected results ?
Dimensioning b as a square (rows & columns equal) would seem to be a red flag.
RequestProSummaryLeaderlaunch DateStatusLocationDescriptionRequirementsUpdated
LOA1234My summaryperson 13/15/2024ActiveSelect Locations DescriptionRequirements
3/11/2024​

Transformed to, but currently stops at column L and does not add the remaining people.
Person 1Person 2Person 3Person 4Person 5Person 6Person 7Person 8Person 9Person 10Person 11Person 12Person 13Person 14Person 15Person 16Person 17
03/15/2024
1234
Person 1
My Summary
03/15/2024
1234
Person 2
My Summary
03/15/2024
1234
Person 3
My Summary
03/15/2024
1234
Person 4
My Summary
03/15/2024
1234
Person 5
My Summary
03/15/2024
1234
Person 6
My Summary
03/15/2024
1234
Person 7
My Summary
03/15/2024
1234
Person 8
My Summary
03/15/2024
1234
Person 9
My Summary
03/15/2024
1234
Person 10
My Summary
03/15/2024
1234
Person 1
My Summary
03/15/2024
1234
Person 1 1
My Summary
03/15/2024
1234
Person 12
My Summary
03/15/2024
1234
Person 13
My Summary
03/15/2024
1234
Person 14
My Summary
03/15/2024
1234
Person 15
My Summary
03/15/2024
1234
Person 16
My Summary
 
Upvote 0
A sample size of 1 is not going to be of much help when your issue seem to be caused by a larger sample size.
When I create multiple lines from your 1 line I get a different result. Duplicates move to row 2 and I don't seem to get the date in the output.
Any reason you don't use Power Query for this ? This would be fairly straight forward in Power Query.
If you want to keep going with VBA I need as a minimum an XL2BB version of a data set that generates the issue at your end.
Alternatively share a data set which you have verified still has the issue via DropBox, Google Drive or some other sharing platform making it available anyone with the link and posting the link here.

Using XL2BB
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
A sample size of 1 is not going to be of much help when your issue seem to be caused by a larger sample size.
When I create multiple lines from your 1 line I get a different result. Duplicates move to row 2 and I don't seem to get the date in the output.
Any reason you don't use Power Query for this ? This would be fairly straight forward in Power Query.
If you want to keep going with VBA I need as a minimum an XL2BB version of a data set that generates the issue at your end.
Alternatively share a data set which you have verified still has the issue via DropBox, Google Drive or some other sharing platform making it available anyone with the link and posting the link here.

Using XL2BB
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
I am not permitted to install XL2BB add-in, so I have to do it the long way. I will create a dataset and post.
 
Upvote 0

Forum statistics

Threads
1,217,367
Messages
6,136,136
Members
449,994
Latest member
Rocky Mountain High

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