Macro or VBA to copy and fill data to a new sheet, different format.

datavizwiz

New Member
Joined
Aug 21, 2018
Messages
5
Hi!

I'm really hoping someone here can help me. I'm going to try and be as concise about my question as possible, but please ask for clarification if needed. I have a fillable PDF where users are given approx. 60-240 schedule choices (depending on which group they are in) which they rank numerically in order of their preference. Their selections are then exported to excel, normalized and imported into access where we determine who received what schedule based on their seniority and their ranking selections.

Obviously best practice is not to have a table with 240 fields (1 for each schedule option) so data normalization currently consists of converting the data structure from 240 fields to 3 fields (where there is 1 record for each scheduleID with it's ranking and a User ID to identify the individual.)
Current state: copying and transpose pasting the schedule data inside of excel and then copying, pasting and filling their user ID. The process for this is the same every time, and I am looking for the best way to automate this process instead of it taking hours (400 people are submitting these forms). Any input on the best way to do this is appreciated. I'm not great very well versed in VBA, but feel that is probably the best method.

RAW DATA AFTER EXPORTING FROM PDF FORM
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]ID[/TD]
[TD]Schedule 1[/TD]
[TD]Schedule 2[/TD]
[TD]Schedule 3[/TD]
[TD]Schedule 4[/TD]
[TD]Schedule 5[/TD]
[/TR]
[TR]
[TD]Person1[/TD]
[TD]U34567[/TD]
[TD]1[/TD]
[TD]7[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Person 2[/TD]
[TD]U29268[/TD]
[TD]10[/TD]
[TD]8[/TD]
[TD]7[/TD]
[TD]6[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]

NEEDED FORMAT
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Schedule ID[/TD]
[TD]Ranking[/TD]
[/TR]
[TR]
[TD]U34567[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]U34567[/TD]
[TD]2[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]U34567[/TD]
[TD]3[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]U34567[/TD]
[TD]4[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]U34567[/TD]
[TD]5[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]U29268[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]U29268[/TD]
[TD]2[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]U29268[/TD]
[TD]3[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]U29268[/TD]
[TD]4[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]U29268[/TD]
[TD]5[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try:
Code:
Sub FillData()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim LastRow2 As Long
    Dim lColumn As Long, ID As Range
    lColumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
    Sheets("Sheet2").Range("A1:C1") = Array("ID", "Schedule ID", "Ranking")
    For Each ID In Sheets("Sheet1").Range("B2:B" & LastRow)
        LastRow2 = Sheets("Sheet2").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
        Sheets("Sheet2").Cells(LastRow2, 1).Resize(lColumn - 2) = ID
        Sheets("Sheet1").Range(Cells(1, 3), Cells(1, lColumn)).Copy
        Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
        ID.Offset(0, 1).Resize(1, lColumn - 2).Copy
        Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
    Next ID
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Change the sheet names to suit your needs.
 
Upvote 0
Thank you so much! This works beautifully! I knew it could be done, but was hoping to avoid spending hours trying to figure out the best way and correct syntax. This will save me hours of time!:)
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
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