Please try this code to see if you get the desired output. As you provided only one sheet so I copied the same data on two other sheets. Therefore this data will also reflect on the Report Analysis Sheet i.e. you will get three reports on the Report Analysis Sheet.
Option Explicit
Sub ReArrangeData()
Dim ws As Worksheet, dws As Worksheet
Dim Srng As Range, rng As Range, crng As Range, ccell As Range
Dim i As Long, r As Long, lr As Long, lc As Long
Application.ScreenUpdating = False
On Error Resume Next
Set dws = Sheets("Report Analysis")
If Err > 0 Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Report Analysis"
Set dws = Sheets("Report Analysis")
End If
i = dws.Cells(Rows.Count, 1).End(xlUp).Row + 1
On Error GoTo 0
For Each ws In Worksheets
If ws.Name <> "Report Analysis" Then
ws.Activate
dws.Range("A" & i) = "ISIN"
dws.Range("B" & i) = "CUSIP"
dws.Range("C" & i) = "Sedol"
dws.Range("D" & i) = "div/coupon rate"
With dws.Range("A" & i & ":D" & i)
.Font.Size = 13
.Font.Bold = True
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlThin
.Interior.ColorIndex = 44
End With
lr = Cells(Rows.Count, 1).End(xlUp).Row
Set Srng = ws.Range("A1:A" & lr)
With Srng
Set rng = .Find(what:="ISIN", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
r = rng.Row
Do
lc = Cells(rng.Row, Columns.Count).End(xlToLeft).Column
Set crng = Range(Cells(rng.Row, 2), Cells(rng.Row, lc))
For Each ccell In crng
If Len(ccell) = 13 Then
dws.Range("A" & Rows.Count).End(3)(2) = ccell
dws.Range("B" & Rows.Count).End(3)(2) = ccell.Offset(-1, 0)
dws.Range("C" & Rows.Count).End(3)(2) = ccell.Offset(1, 0)
dws.Range("D" & Rows.Count).End(3)(2) = ccell.Offset(5, 0)
Exit For
End If
Next ccell
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And r <> rng.Row
End If
End With
End If
i = dws.Cells(Rows.Count, 1).End(xlUp).Row + 3
Next ws
dws.Columns.AutoFit
Application.ScreenUpdating = True
dws.Activate
MsgBox "Finished."
End Sub
Please find the attached sheet and click on the Green Button on Sheet1 to get the desired output on Report Analysis Sheet.
Bookmarks