Sub CrossTabToDatabase()
Dim DataTable As Range, OutputRange As Range
Dim RowOutput As Long
Dim r As Long, c As Long
Dim WS As Worksheet
On Error Resume Next
Set DataTable = ActiveCell.CurrentRegion
If DataTable.Count = 1 Or DataTable.Rows.Count < 3 Then
MsgBox "Select a cell within the summary table", vbCritical
Exit Sub
End If
DataTable.Select
Set WS = Sheets.Add
Set OutputRange = Application.InputBox(prompt:="Select a cell starting where you'd like to output the new datatable.", Type:=8)
' Convert the range
RowOutput = 2
Application.ScreenUpdating = False
OutputRange.Range("A1:C3") = Array("Column1", "Column2", "Column3")
For r = 2 To DataTable.Rows.Count
For c = 2 To DataTable.Columns.Count
OutputRange.Cells(RowOutput, 1) = DataTable.Cells(r, 1)
OutputRange.Cells(RowOutput, 2) = DataTable.Cells(1, c)
OutputRange.Cells(RowOutput, 3) = DataTable.Cells(r, c)
OutputRange.Cells(RowOutput, 3).NumberFormat = DataTable.Cells(r, c).NumberFormat
RowOutput = RowOutput + 1
Next c
Next r
End Sub