Hi HangMan
Try this
Option Explicit
Sub Reverse_Engineer()
Dim ws As Worksheet, ws1 As Worksheet
Dim rng As Range, szCell As Range
Dim i As Long, j As Long, LR As Long, LC As Long, LC1 As Long, cnt As Long
Dim szLastValue As String
Set ws = Sheets("Source Data")
Set ws1 = Sheets("Outcome")
Application.ScreenUpdating = False
With ws1
.Cells.Clear
ws.Cells.Copy Destination:=.Range("A1")
.Activate
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set rng = .Range("A2:A" & LR)
For i = LR To 2 Step -1
LC1 = .Range(.Cells(i, 1), (.Cells(i, LC))).Find(What:="*", LookIn:=xlValues, _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
If LC1 > 4 Then
cnt = 1
.Cells(i, 1).Offset(1, 0).Resize((((LC1 - 1) / 3) - 1), 1).EntireRow.Insert
For j = 5 To LC1 Step 3
.Cells(i, j).Resize(1, 3).Copy
.Range(.Cells(i + cnt, "B"), (.Cells(i + cnt, "B"))).PasteSpecial
cnt = cnt + 1
Next j
End If
Next i
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
.Range("A2:A" & LR).Select
szLastValue = ""
For Each szCell In Selection.Cells
If Trim(szCell.Value) <> "" Then
szLastValue = szCell.Value
Else
If szLastValue <> "" Then szCell.Value = szLastValue
End If
Next szCell
.Range(.Cells(1, 5), .Cells(1, LC)).EntireColumn.Delete
.Range("B1").Value = "Country"
.Range("C1").Value = "Animal"
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Bookmarks