View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default Copy columns by Header and select all data (non-contiguous) from those columns

KeriM wrote:

Auric__ Wrote:
KeriM wrote:
That works great! The only problem I'm running into is the pasting. I
need to paste it all in a new workbook and when I try to dump the
copy into the new workbook, it overwrites the previously pasted
column. I tried designating destination columns, but that means a new
line of code for each copied/pasted column (plus I'm having trouble
getting back into the loop to copy the next section). Is there anyway
to select all the required columns and then copy/paste that entire
selection?


I would just move over 1 column with each paste operation. Try this
(not thoroughly tested, but gives the appearance of working):

[snip]
Works perfectly. I just had to add a line to activate my data worksheet
since the code is written to create the new workbook before the loop, so
it takes the new worksheet as the active sheet so it was copying/pasting
blank cells. The only other problem i have is that it's copying/pasting
the last column twice.


Whoops. At the very end of the sub...

targetSheet.Paste Destination:=targetCell
'here is where we move over
Set targetCell = targetCell.Offset(0, 1)
targetSheet.Paste Destination:=targetCell
End Select
Next
End Sub

....delete the second copy of "targetSheet.Paste Destination:=targetCell", the
one right above "End Select". (That was from my testing; forgot to remove
it.)

--
- What's the winning lottery numbers?
- If I knew that, I wouldn't be working here!