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
NameIDSchedule 1Schedule 2Schedule 3Schedule 4Schedule 5
Person1U345671710114
Person 2U29268108764

<tbody>
</tbody>

NEEDED FORMAT
IDSchedule IDRanking
U3456711
U3456727
U34567310
U34567411
U3456754
U29268110
U2926828
U2926837
U2926846
U2926854

<tbody>
</tbody>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

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