Thread: combine columns
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default combine columns

oops. I forgot to set it the first time:

Option Explicit
Sub testme01()

Dim wks As Worksheet
Dim RngToCopy As Range
Dim DestCell As Range
Dim iCol As Long
Dim FirstCol As Long
Dim LastCol As Long
Dim LastRow as long

Set wks = Worksheets("sheet1")

With wks
lastrow = .cells(.rows.count,"A").end(xlup).row
FirstCol = 2
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

DestCell = .cells(lastrow+1,"A")

For iCol = FirstCol To LastCol
Set RngToCopy = .Range(.Cells(1, iCol), _
.Cells(lastrow, iCol))

DestCell.Resize(RngToCopy.Rows.Count, 1).Value _
= RngToCopy.Value

Set DestCell = destcell.offset(rngtocopy.rows.count)

Next iCol

.Range(.Columns(FirstCol), .Columns(LastCol)).Delete

End With

End Sub

wrote:

I get
object variable or with block variable not set
and the routine stops


--

Dave Peterson