View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Copy/paste Column

Hi Ron -

Thanks for the code .... it works perfectly and I think I can actually
follow what it's doing!

Rgds, Ray



Ron de Bruin wrote:
Try this

Copy column A from the activeworkbook to the workbook ron.xls (note: this file must be open)

Sub copy_4()
Dim sourceRange As Range
Dim destrange As Range
Dim Lc As Integer
Dim WB1 As Workbook
Dim WB2 As Workbook
Set WB1 = ActiveWorkbook
Set WB2 = Workbooks("ron.xls")

Lc = Lastcol(WB2.Sheets(1)) + 1
Set sourceRange = WB1.Sheets(1).Columns("A:A")
Set destrange = WB2.Sheets(1).Columns(Lc)
sourceRange.Copy destrange
End Sub

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ray" wrote in message oups.com...
I need help before I go crazy .... I've spent the last 2hrs searching
for code that I could modify to do what I need (and found plenty of
examples), and it seems simple enough, but i just CANNOT make it work
for my workbook...Here's my scenario:

I'd like to copy the first column from WB1 to the first empty column in
WB2 (both books have only one sheet). See what I mean, sounds simple
.... but I can't figure it out....

TIA,
Ray