Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Copy/paste Column

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy/paste Column

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

  #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


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

Hello again ....

While further developing my Workbook, I came across a scenario that I'd
like to avoid as it would cause fairly major issues if it occurred....

BEFORE copying ColA from WB1 to WB2, I need to insert code that
compares the value in Cell A2 (in WB1) with the value in Row2 of the
last column in WB2. If the values are the same, I'd like a msgbox to
popup declaring the issue and quitting the process.

I'm quite sure I need to use the Offset properties here, but the code
to identify & compare the two values is quite confusing for a newbie
like me.

TIA...
//ray



Ray wrote:
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy/paste Column

Hi Ray

Untested, Try this one

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

If WB1.Sheets(1).Range("A2") = WB2.Sheets(1).Cells(2, Lc - 1) Then
MsgBox "Values are the same"
Else
Set sourceRange = WB1.Sheets(1).Columns("A:A")
Set destrange = WB2.Sheets(1).Columns(Lc)
sourceRange.Copy destrange
End If

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...
Hello again ....

While further developing my Workbook, I came across a scenario that I'd
like to avoid as it would cause fairly major issues if it occurred....

BEFORE copying ColA from WB1 to WB2, I need to insert code that
compares the value in Cell A2 (in WB1) with the value in Row2 of the
last column in WB2. If the values are the same, I'd like a msgbox to
popup declaring the issue and quitting the process.

I'm quite sure I need to use the Offset properties here, but the code
to identify & compare the two values is quite confusing for a newbie
like me.

TIA...
//ray



Ray wrote:
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


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

Again Ron, thanks VERY much for your help .... it worked perfectly! I
just added some code to close the workbooks and it's done!


Ron de Bruin wrote:
Hi Ray

Untested, Try this one

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

If WB1.Sheets(1).Range("A2") = WB2.Sheets(1).Cells(2, Lc - 1) Then
MsgBox "Values are the same"
Else
Set sourceRange = WB1.Sheets(1).Columns("A:A")
Set destrange = WB2.Sheets(1).Columns(Lc)
sourceRange.Copy destrange
End If

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...
Hello again ....

While further developing my Workbook, I came across a scenario that I'd
like to avoid as it would cause fairly major issues if it occurred....

BEFORE copying ColA from WB1 to WB2, I need to insert code that
compares the value in Cell A2 (in WB1) with the value in Row2 of the
last column in WB2. If the values are the same, I'd like a msgbox to
popup declaring the issue and quitting the process.

I'm quite sure I need to use the Offset properties here, but the code
to identify & compare the two values is quite confusing for a newbie
like me.

TIA...
//ray



Ray wrote:
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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy/paste Column

You can steal code from this macro/function to check if the workbook is open and if it is not open
open it

http://www.rondebruin.nl/copy1.htm#workbook



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


"Ray" wrote in message oups.com...
Again Ron, thanks VERY much for your help .... it worked perfectly! I
just added some code to close the workbooks and it's done!


Ron de Bruin wrote:
Hi Ray

Untested, Try this one

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

If WB1.Sheets(1).Range("A2") = WB2.Sheets(1).Cells(2, Lc - 1) Then
MsgBox "Values are the same"
Else
Set sourceRange = WB1.Sheets(1).Columns("A:A")
Set destrange = WB2.Sheets(1).Columns(Lc)
sourceRange.Copy destrange
End If

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...
Hello again ....

While further developing my Workbook, I came across a scenario that I'd
like to avoid as it would cause fairly major issues if it occurred....

BEFORE copying ColA from WB1 to WB2, I need to insert code that
compares the value in Cell A2 (in WB1) with the value in Row2 of the
last column in WB2. If the values are the same, I'd like a msgbox to
popup declaring the issue and quitting the process.

I'm quite sure I need to use the Offset properties here, but the code
to identify & compare the two values is quite confusing for a newbie
like me.

TIA...
//ray



Ray wrote:
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save column J only using copy/paste & temporary copy mikeburg[_85_] Excel Programming 2 June 7th 06 05:37 PM
Copy and paste values for particular column Derek Y via OfficeKB.com[_2_] Excel Programming 6 October 17th 05 04:00 PM
Copy cell and paste in same column April Excel Programming 1 March 2nd 05 12:29 PM
Copy Cell and Paste in Same Column Only April Excel Programming 0 February 16th 05 02:57 PM
Copy Column and Paste steveh[_3_] Excel Programming 2 February 2nd 04 01:36 PM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"