Hi,
I have a sheet, with a dataset which is 18 columns, however, further datasets of 18 columns are repeated throughout the sheet horizontally. I need to stack this data vertically. below is a crude example of the table i have and what i need to do is take all the data outside of columns a and b, and to add them to bottom of column a and b ideally without any spaces.
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[/TR]
[TR]
[TD]Set 1[/TD]
[TD]Set1[/TD]
[TD]Set 2[/TD]
[TD]Set 2[/TD]
[TD]Set 3[/TD]
[TD]Set 3[/TD]
[TD]Set 4[/TD]
[TD]Set 4[/TD]
[TD]Set 5[/TD]
[TD]Set 5[/TD]
[/TR]
[TR]
[TD]acb[/TD]
[TD]acb[/TD]
[TD]abc1[/TD]
[TD]abc1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bcd[/TD]
[TD]bcd[/TD]
[TD]bcd1[/TD]
[TD]bcd1[/TD]
[TD]bcd2[/TD]
[TD]bcd2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]cde[/TD]
[TD]cde[/TD]
[TD]cde1[/TD]
[TD]cde1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]def[/TD]
[TD]def[/TD]
[TD]def1[/TD]
[TD]def1[/TD]
[TD]def2[/TD]
[TD]def2[/TD]
[TD]def3[/TD]
[TD]def3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]efg[/TD]
[TD]efg[/TD]
[TD]efg1[/TD]
[TD]efg1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]fgh[/TD]
[TD]fgh[/TD]
[TD]fgh1[/TD]
[TD]fgh1[/TD]
[TD]fgh2[/TD]
[TD]fgh2[/TD]
[TD]fgh3[/TD]
[TD]fgh3[/TD]
[TD]fgh4[/TD]
[TD]fgh4[/TD]
[/TR]
[TR]
[TD]ghi[/TD]
[TD]ghi[/TD]
[TD]ghi1[/TD]
[TD]ghi1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ghi[/TD]
[TD]ghi[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have been trying to write a macro which achieves this however, i am getting a 1004 error in relation to an advanced filter i am trying to perform.
it fails on line:
cr.AdvancedFilter Action:=xlFilterCopy, criteriarange:=TS.Range(.Cells(1, 1)), copytorange:=TS.Range(.Cells(lr + 1, 1)), Unique:=True
Can anyone help on this? is there a better way of achieving what i am after?
Cheers,
Dan.
I have a sheet, with a dataset which is 18 columns, however, further datasets of 18 columns are repeated throughout the sheet horizontally. I need to stack this data vertically. below is a crude example of the table i have and what i need to do is take all the data outside of columns a and b, and to add them to bottom of column a and b ideally without any spaces.
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[/TR]
[TR]
[TD]Set 1[/TD]
[TD]Set1[/TD]
[TD]Set 2[/TD]
[TD]Set 2[/TD]
[TD]Set 3[/TD]
[TD]Set 3[/TD]
[TD]Set 4[/TD]
[TD]Set 4[/TD]
[TD]Set 5[/TD]
[TD]Set 5[/TD]
[/TR]
[TR]
[TD]acb[/TD]
[TD]acb[/TD]
[TD]abc1[/TD]
[TD]abc1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bcd[/TD]
[TD]bcd[/TD]
[TD]bcd1[/TD]
[TD]bcd1[/TD]
[TD]bcd2[/TD]
[TD]bcd2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]cde[/TD]
[TD]cde[/TD]
[TD]cde1[/TD]
[TD]cde1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]def[/TD]
[TD]def[/TD]
[TD]def1[/TD]
[TD]def1[/TD]
[TD]def2[/TD]
[TD]def2[/TD]
[TD]def3[/TD]
[TD]def3[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]efg[/TD]
[TD]efg[/TD]
[TD]efg1[/TD]
[TD]efg1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]fgh[/TD]
[TD]fgh[/TD]
[TD]fgh1[/TD]
[TD]fgh1[/TD]
[TD]fgh2[/TD]
[TD]fgh2[/TD]
[TD]fgh3[/TD]
[TD]fgh3[/TD]
[TD]fgh4[/TD]
[TD]fgh4[/TD]
[/TR]
[TR]
[TD]ghi[/TD]
[TD]ghi[/TD]
[TD]ghi1[/TD]
[TD]ghi1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ghi[/TD]
[TD]ghi[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have been trying to write a macro which achieves this however, i am getting a 1004 error in relation to an advanced filter i am trying to perform.
Code:
Sub Stackrepeats()
Dim lr As Long
Dim lastcol As Long
Dim cr As Range
Dim TS As Worksheet
Dim NLR As Long
Set TS = ActiveSheet
Do Until lastcol = 18
With TS.UsedRange
lr = Cells(Rows.Count, 1).End(xlUp).Row
lastcol = .Columns(.Columns.Count).Column
Set cr = .Range(.Cells(1, 19), .Cells(lr, lastcol))
cr.AdvancedFilter Action:=xlFilterCopy, criteriarange:=TS.Range(.Cells(1, 1)), copytorange:=TS.Range(.Cells(lr + 1, 1)), Unique:=True
cr.ClearContents
Application.CutCopyMode = False
End With
Loop
End Sub
it fails on line:
cr.AdvancedFilter Action:=xlFilterCopy, criteriarange:=TS.Range(.Cells(1, 1)), copytorange:=TS.Range(.Cells(lr + 1, 1)), Unique:=True
Can anyone help on this? is there a better way of achieving what i am after?
Cheers,
Dan.