Code:'______________________________________________________________ '______________________________________________________________ ' ' Slightly modified with lots of Comments Sub RickRothsteinsConcatenatingBalls() 'NOTE: Change the ## A1 to the address of the top left cell of your 'existing data and change the '### G1 to the address of the top left cell where you want the converted table to go to. Const ExistingTableAnyCellLocation As String = "A1" '## Const NewTableLHCornerLocation As String = "G1" '### Dim SourceTableRange As Range 'Give a name and allow all methods and properties of range object to it Set SourceTableRange = Range(ExistingTableAnyCellLocation).CurrentRegion ' Give this a specific Range. CurrentRegiuon Property applied to a cell returns a complete range incorporating that cell and any ranges that it either is in or touches Dim SourceTableRangeTableRowsCount As Byte ' For a small Table allow it to hve up to 255 Rows Let SourceTableRangeTableRowsCount = SourceTableRange.Rows.Count ' This returns the number of rows in the original table Dim FinalTableFirstColumnRange As Range Set FinalTableFirstColumnRange = Range(NewTableLHCornerLocation).Resize(SourceTableRangeTableRowsCount) ' Here the resize Property applied to the Range G1 (or Cell G1 here) returns a range increased by the row number, that is to say a range equal to the first column SourceTableRange.Columns(1).Resize(, 2).Copy Destination:=FinalTableFirstColumnRange ' This is one way of copying the first two columns of the original table to The final table FinalTableFirstColumnRange.Columns(2).NumberFormat = "@" ' This gives a format to the second column in the final Table 'FinalTableFirstColumnRange.Offset(0, 1) = _ 'Evaluate("IF(ROW()," & SourceTableRange.Columns(2).Address & "&"" - ""&" & SourceTableRange.Columns(3).Address & "&"" - ""&" & SourceTableRange.Columns(4).Address & ")") 'FinalTableFirstColumnRange.Offset(0, 1) = _ 'Evaluate(" " & SourceTableRange.Columns(2).Address & "&"" - ""&" & SourceTableRange.Columns(3).Address & "&"" - ""&" & SourceTableRange.Columns(4).Address & "") FinalTableFirstColumnRange.Offset(0, 1) = _ Evaluate(" " & SourceTableRange.Columns(2).Address & " " & "&"" - ""&" & " " & SourceTableRange.Columns(3).Address & " " & "&"" - ""&" & "" & SourceTableRange.Columns(4).Address & "") SourceTableRange.Columns(5).Copy Destination:=FinalTableFirstColumnRange.Offset(, 2) 'Column 5 of Original table is copied to column 3 of the Final table by setting the destination to 2 colums offset from the first column FinalTableFirstColumnRange.Cells(1, 0).Offset(0, 1).Value = "Numbers" ' The current heading in the second column is finally overwriten with "Numbers". This is done here by putting the value"Numbers" in the cell which is offset by 1 column to the first cell in the Final Table First Column End Sub 'RickRothsteinsConcatenatingBalls() ' ''_______________________________________________________________________________ '__________________________________________________________________________________ '______________________________________________________________ ' Replacing the line I do not fully understand with a 3 line loop Sub RickRothsteinsConcatenatingBalls2() Dim j As Byte 'NOTE: Change the ## A1 to the address of the top left cell of your 'existing data and change the '### G1 to the address of the top left cell where you want the converted table to go to. Const ExistingTableAnyCellLocation As String = "A1" '## Const NewTableLHCornerLocation As String = "G1" '### Dim SourceTableRange As Range 'Give a name and allow all methods and properties of range object to it Set SourceTableRange = Range(ExistingTableAnyCellLocation).CurrentRegion ' Give this a specific Range. CurrentRegiuon Property applied to a cell returns a complete range incorporating that cell and any ranges that it either is in or touches Dim SourceTableRangeTableRowsCount As Byte ' For a small Table allow it to have up to 255 Rows Let SourceTableRangeTableRowsCount = SourceTableRange.Rows.Count ' This returns the number of rows in the original table Dim FinalTableFirstColumnRange As Range Set FinalTableFirstColumnRange = Range(NewTableLHCornerLocation).Resize(SourceTableRangeTableRowsCount) ' Here the resize Property applied to the Range G1 (or Cell G1 here) returns a range increased by the row number, that is to say a range equal to the first column SourceTableRange.Columns(1).Resize(, 2).Copy Destination:=FinalTableFirstColumnRange ' This is one way of copying the first two columns of the original table to The final table FinalTableFirstColumnRange.Columns(2).NumberFormat = "@" ' This gives a format to the second column in the final Table For j = 2 To SourceTableRangeTableRowsCount Step 1 ' For each column of data FinalTableFirstColumnRange.Cells(1, 1).Offset(j - 1, 1) = Evaluate("" & SourceTableRange.Cells(j, 2).Address & "" & "&"" - ""&" & "" & SourceTableRange.Cells(j, 3).Address & "" & "&"" - ""&" & "" & SourceTableRange.Cells(j, 4).Address & "") ' the evaluate fuction can be used in VBA to give the reults from a formula in a normal Excel Spreadsheet. Hier we use it simply to give the results of a formula something of the form =B2 & " - " & C2 & " - " & D2. Just a convenient way of doung the concantenating. Further we here maks the addresses B2 C2 D2 variable in a loop. A very tricky syntax!!! Next j SourceTableRange.Columns(5).Copy Destination:=FinalTableFirstColumnRange.Offset(, 2) 'Column 5 of Original table is copied to column 3 of the Final table by setting the destination to 2 colums offset from the first column FinalTableFirstColumnRange.Cells(1, 0).Offset(0, 1).Value = "Numbers" ' The current heading in the second column is finally overwriten with "Numbers". This is done here by putting the value"Numbers" in the cell which is offset by 1 column to the first cell in the Final Table First Column End Sub 'RickRothsteinsConcatenatingBalls2() '
Bookmarks