ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copying entire column (https://www.excelbanter.com/excel-programming/311938-copying-entire-column.html)

Charlie[_8_]

copying entire column
 
I have a workbook open with 3 columns of data & then open a second.

Set newApp = New Excel.Application
newApp.Workbooks.Open xlsFile

I then get some header info from the 2nd workbbok
Set row = human.Worksheets(1).Rows(1)
For i = 2 To maxHdr + 1
hdr(i - 1) = UCase(row.Cells(i).Text)
Next i

Next I try to copy the 1st column from the 2nd workbook to the 1st
column of the 1st workbook - overlaying the existing data in the 1st
column
Dim inCol, outCol As Range
Set inCol = human.Worksheet(1).Columns(1)
Set outCol = Application.ActiveWorkbook.Worksheets(1).Columns(1 )
inCol.Copy Destination:=Application.ActiveWorkbook.Worksheets (1).Columns(1)

I've tried several permeations of the copy statement but it never gets
displayed.
Any help appreciated. thanks...charlie

John Mansfield[_2_]

copying entire column
 
Charlie, try

Sub CopyColumns()
Dim RngSrc As Range
Dim RngDest As Range
Set RngSrc = Workbooks("Book2").Sheets
("Sheet1").Columns(1)
Set RngDest = Workbooks("Book3").Sheets
("Sheet1").Columns(1)
RngSrc.Copy RngDest
End Sub

Regards,

John Mansfield
The Planning Deskbook
http://www.pdbook.com


-----Original Message-----
I have a workbook open with 3 columns of data & then open

a second.

Set newApp = New Excel.Application
newApp.Workbooks.Open xlsFile

I then get some header info from the 2nd workbbok
Set row = human.Worksheets(1).Rows(1)
For i = 2 To maxHdr + 1
hdr(i - 1) = UCase(row.Cells(i).Text)
Next i

Next I try to copy the 1st column from the 2nd workbook

to the 1st
column of the 1st workbook - overlaying the existing data

in the 1st
column
Dim inCol, outCol As Range
Set inCol = human.Worksheet(1).Columns(1)
Set outCol = Application.ActiveWorkbook.Worksheets

(1).Columns(1)
inCol.Copy

Destination:=Application.ActiveWorkbook.Worksheets
(1).Columns(1)

I've tried several permeations of the copy statement but

it never gets
displayed.
Any help appreciated. thanks...charlie
.


Charlie[_8_]

copying entire column
 
I tried that but it doesn't seem to work.
In you example are "Book2" and "Book3" the actual text name of the
path & file name of the workbooks, and "Sheet1" the name of the sheet
in the workbook?
That is what I put in there.


All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com