View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Copy columns and paste with blank column between


combined with Garrys suggestion you can try:

Sub CopyCols()

Dim LCol As Integer

Dim LRow As Long

Dim varOut As Variant

Dim i As Integer

Dim j As Integer



With Sheets("Sheet1")

LCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

j = 1

For i = 1 To LCol

LRow = .Cells(.Rows.Count, i).End(xlUp).Row

varOut = .Range(.Cells(1, i), .Cells(LRow, i))

Sheets("Sheet2").Cells(Rows.Count, j).End(xlUp) _

.Offset(1, 0).Resize(rowsize:=LRow) = varOut

j = j + 2

Next

End With

End Sub


Regards

Claus B.


Well, at least my thought process was heading in the right direction now that I see these workable samples.

I knew I would need a variable to determine the number of columns on sheet 1 which I can do well enough and a method to advance the copied columns to sheet 2by two. I didn't know what that was going to look like. Not so bad seeing it properly written, and I can read it pretty well. Composing is another thing.

And I'm getting more adept at using this method as you suggest, Garry. Although here you are using .Value on target and source. Don't you set both target and source to ranges? Probably confusing what you are trying to convey.
rngTarget.Value = rngSource.Value



I'm missing your point on the InputBox suggestion for

<When your source/target ranges vary

When you prompt for a destination range, isn't the "uppermost left cell" really all you need, ranges same or different?

Thanks to both of you for the info.

Howard