PC Review


Reply
Thread Tools Rate Thread

Copy/paste Column

 
 
Ray
Guest
Posts: n/a
 
      27th Nov 2006
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 With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      27th Nov 2006
As always, post your efforts

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Ray" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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 With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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 With Quote
 
Ray
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> >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 With Quote
 
Ray
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> > >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 With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> > >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 With Quote
 
Ray
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> >> > >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 With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      27th Nov 2006
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> > 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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> >> > >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy/paste in the next column Nicawette Microsoft Excel Programming 4 30th Jan 2010 04:03 AM
Copy/paste a column? Steve Microsoft Outlook 1 16th Mar 2008 01:17 AM
Copy and Paste down the column ExcelNovice Microsoft Excel Programming 2 31st Dec 2007 11:27 PM
Save column J only using copy/paste & temporary copy mikeburg Microsoft Excel Programming 2 7th Jun 2006 05:37 PM
Copy Column and Paste =?Utf-8?B?c3RldmVo?= Microsoft Excel Programming 2 2nd Feb 2004 01:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:35 AM.