VBA programmer feedback
Hi Bob-
Thanks for the feedback.
Jason
-----Original Message-----
Hi Jason,
A couple of relatively minor points.
You use With to qualify an object, but for a single
statement this has no
value, so
With Sheets.Add
.Name = "Alldata"
End With
should be
Sheets.Add.Name = "Alldata"
Also, you set worksheet objects most of the time, but
also use implicit
referencing, which, with the multiple sheets referenced,
makes it more
difficult to follow than it need be.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"Jason Morin" wrote in message
...
I'm not a programmer, so I would appreciate any feedback
on this short macro I created. It takes multiple columns
of variable lengths and piles then in column A on a new
sheet. No error-trapping for more than 65,536 rows or an
empty column. Thanks. Jason
Sub OneColumn()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
''''''''''''''''''''''''''''''''''''''''''
Dim ilastcol As Long
Dim ilastrow As Long
Dim jlastrow As Long
Dim colndx As Long
Dim ws As Worksheet
Dim myrng As Range
Dim idx As Integer
Set ws = ActiveWorkbook.activesheet
ilastcol = Cells(1, Columns.Count).End(xlToLeft).Column
With Sheets.Add
.Name = "Alldata"
End With
idx = Sheets("Alldata").Index
Sheets(idx + 1).Activate
For colndx = 1 To ilastcol
ilastrow = ws.Cells(Rows.Count, colndx).End(xlUp).Row
jlastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
..End(xlUp).Row
Set myrng = Range(Cells(1, colndx), _
Cells(ilastrow, colndx))
With myrng
.Copy Sheets("Alldata").Cells(jlastrow + 1, 1)
End With
Next
Sheets("Alldata").Rows("1:1").EntireRow.Delete
End Sub
.
|