Dear all,
I have no macro experience and would greatly appreciate it if you could look at the attachment.
It's seems rather complicated (to me anyway).
Your help would be greatly appreciated
Dear all,
I have no macro experience and would greatly appreciate it if you could look at the attachment.
It's seems rather complicated (to me anyway).
Your help would be greatly appreciated
Try this macro
for it to work you must name the input range "SourceTable" (A1:I10 in your example, ie including the headings row).
select the first cell where you want the output to begin (cell A14 in your example) and run the macro
![]()
Sub create_table() Dim x As Long, Vessel As String, BLDate, n As Long, StartCell, ColNum As Long, ColCount As Long, SourceCol As Long Vessel = Range("SourceRange").Rows(2).Columns(1).Value BLDate = Range("SourceRange").Rows(2).Columns(2).Value StartCell = ActiveCell.Address 'type 1st set of column headings For n = 1 To Range("SourceRange").Columns.Count ActiveCell.Offset(0, n - 1).Value = Range("SourceRange").Columns(n).Rows(1).Value Next n ActiveCell.Offset(1, 0).Select ColCount = 2 ColNum = 2 For x = 2 To Range("SourceRange").Rows.Count If Range("SourceRange").Columns(1).Rows(x).Value = Vessel And Range("SourceRange").Columns(2).Rows(x).Value = BLDate Then ActiveCell.Value = Vessel ActiveCell.Offset(0, 1).Value = BLDate For n = 3 To Range("SourceRange").Columns.Count ActiveCell.Offset(0, ColNum).Value = Range("SourceRange").Columns(n).Rows(x).Value ColNum = 1 + ColNum Next n If ColNum > ColCount Then ColCount = ColNum Else Vessel = Range("SourceRange").Rows(x).Columns(1).Value BLDate = Range("SourceRange").Rows(x).Columns(2).Value If ActiveCell.Value <> "" Then ActiveCell.Offset(1, 0).Select ColNum = 2 n = 3 x = x - 1 End If Next x Range(StartCell).Select x = 3 For n = 2 To ColCount - 1 ActiveCell.Offset(0, n).Value = Range("SourceRange").Columns(x).Rows(1).Value If x = Range("SourceRange").Columns.Count Then x = 3 Else x = x + 1 Next n End Sub
Wow Nicky! I can't thank you enough for taking the time to write that.
I'm about to give it a go...
Again, you've made such an effort and I'm very grateful!
Hi Nicky, It worked!!! I'm just so thankful!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks