Move/Copy data to corresponding column headers in table

trustmywords

New Member
Joined
Feb 22, 2011
Messages
9
I have more tables in spreadsheet. I have an empty master table with all column headers. I have all the data in A1 with corresponding headers in B1. Likewise i have more tables within A1 and B1, each table separated by a blank row.

A1 B1 c1.D1 etc,....Name Spouse Add1 City1 Phone Cell Fax

John Lipton Name
Anna Spouse
232 Main st Add1
Austin City1
232 219-5322 Phone
939 333-2419 Cell
232 219-2419 Fax

Mark Henry Name
2219 NE st Add1
Miami City
343 225-1199 Phone
343 225-1566 Fax


I want the output like ...


Name Spouse Add1 City1 Phone Cell Fax
John Lipton Anna 232 Main st Austin 232 219-5322 939 333-2419 232 219-2419
Mark Henry 2219 NE st Miami 343 225-1199 343 225-1566

I have 500 tables like this. is there any macro that when ran, the contents of a table moves or copies to the master table under the corresponding column headers. I dont know to edit macro, i just know to run. Can anyone suggest a best solution for this. The column headers are for illustration only, can anyone provide me with good solution.

Thanks in advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Add a module and insert this.

You'll have to adjust the sheet names.

Code:
Sub TransposeData()
Dim wsMaster As Worksheet
Dim wsList As Worksheet
Dim LastRowM As Long
Dim LastRowL As Long
Dim aRow As Range
Set wsMaster = Worksheets("Master")
Set wsList = Worksheets("List")
With wsMaster
'Next available row
    LastRowM = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End With
With wsList
    'Lastrow
    LastRowL = .Cells(.Rows.Count, 1).End(xlUp).Row
    
    For Each aRow In .Range("A1:A" & LastRowL)
        'If a empty cell found, then increment
        'Master lastrow
        If aRow = "" Then
            LastRowM = LastRowM + 1
        End If
        
        'Look for column name in cell contents.
        Select Case aRow.Offset(, 1)
        
        Case "Name"
        wsMaster.Range("A" & LastRowM).Value = aRow
        
        Case "Spouse"
        wsMaster.Range("B" & LastRowM).Value = aRow
        
        Case "Add1"
        wsMaster.Range("C" & LastRowM).Value = aRow
        
        Case "City1"
        wsMaster.Range("D" & LastRowM).Value = aRow
        
        Case "Phone"
        wsMaster.Range("E" & LastRowM).Value = aRow
        
        Case "Cell"
        wsMaster.Range("F" & LastRowM).Value = aRow
        
        Case "Fax"
        wsMaster.Range("G" & LastRowM).Value = aRow
        End Select
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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