PC Review


Reply
Thread Tools Rate Thread

Copy values only

 
 
Dr. Schwartz
Guest
Posts: n/a
 
      31st Jan 2008
In Excel 2003 what do I need to change in this piece of code to only copy
values?

ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
Cells(Jour_Rw, 18)).copy
Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)

An easy one I guess, but still...

Thanks
The Doctor
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      31st Jan 2008
One way


Dim SourceRange As Range, DestRange As Range

Set SourceRange = ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1), Cells(Jour_Rw, 18))

Set DestRange = wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)

'We make DestRange the same size as SourceRange and use the Value
'property to give DestRange the same values
With SourceRange
Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)
End With
DestRange.Value = SourceRange.Value


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dr. Schwartz" <(E-Mail Removed)> wrote in message news:0B9A9B2D-DBD4-4A05-80DD-(E-Mail Removed)...
> In Excel 2003 what do I need to change in this piece of code to only copy
> values?
>
> ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
> Cells(Jour_Rw, 18)).copy
> Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>
> An easy one I guess, but still...
>
> Thanks
> The Doctor

 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      31st Jan 2008
You cannot use the copy:destination construct when you want to restrict the
copy use the following instead

ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
Cells(Jour_Rw, 18)).Copy
wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1).PasteSpecial
Paste:=xlPasteValues
Application.CutCopyMode = False

--

Regards,
Nigel
(E-Mail Removed)



"Dr. Schwartz" <(E-Mail Removed)> wrote in message
news:0B9A9B2D-DBD4-4A05-80DD-(E-Mail Removed)...
> In Excel 2003 what do I need to change in this piece of code to only copy
> values?
>
> ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
> Cells(Jour_Rw, 18)).copy
> Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>
> An easy one I guess, but still...
>
> Thanks
> The Doctor


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Jan 2008
Watch your unqualified ranges:

Set SourceRange = ThisWorkbook.Worksheets("source_sheet") _
.Range(Cells(Jour_Rw, 1), Cells(Jour_Rw, 18))

I'd use:
with thisworkbook.worksheets("source_sheet")
Set SourceRange = .Range(.Cells(Jour_Rw, 1), .Cells(Jour_Rw, 18))
End with

(a couple of extra dots.)


Ron de Bruin wrote:
>
> One way
>
> Dim SourceRange As Range, DestRange As Range
>
> Set SourceRange = ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1), Cells(Jour_Rw, 18))
>
> Set DestRange = wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>
> 'We make DestRange the same size as SourceRange and use the Value
> 'property to give DestRange the same values
> With SourceRange
> Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)
> End With
> DestRange.Value = SourceRange.Value
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
> "Dr. Schwartz" <(E-Mail Removed)> wrote in message news:0B9A9B2D-DBD4-4A05-80DD-(E-Mail Removed)...
> > In Excel 2003 what do I need to change in this piece of code to only copy
> > values?
> >
> > ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
> > Cells(Jour_Rw, 18)).copy
> > Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
> >
> > An easy one I guess, but still...
> >
> > Thanks
> > The Doctor


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Jan 2008
Oops. I see you copied|pasted from the OP.

Ron de Bruin wrote:
>
> One way
>
> Dim SourceRange As Range, DestRange As Range
>
> Set SourceRange = ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1), Cells(Jour_Rw, 18))
>
> Set DestRange = wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>
> 'We make DestRange the same size as SourceRange and use the Value
> 'property to give DestRange the same values
> With SourceRange
> Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)
> End With
> DestRange.Value = SourceRange.Value
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
> "Dr. Schwartz" <(E-Mail Removed)> wrote in message news:0B9A9B2D-DBD4-4A05-80DD-(E-Mail Removed)...
> > In Excel 2003 what do I need to change in this piece of code to only copy
> > values?
> >
> > ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
> > Cells(Jour_Rw, 18)).copy
> > Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
> >
> > An easy one I guess, but still...
> >
> > Thanks
> > The Doctor


--

Dave Peterson
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      31st Jan 2008
Yes

Good catch Dave



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave Peterson" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Oops. I see you copied|pasted from the OP.
>
> Ron de Bruin wrote:
>>
>> One way
>>
>> Dim SourceRange As Range, DestRange As Range
>>
>> Set SourceRange = ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1), Cells(Jour_Rw, 18))
>>
>> Set DestRange = wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>>
>> 'We make DestRange the same size as SourceRange and use the Value
>> 'property to give DestRange the same values
>> With SourceRange
>> Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)
>> End With
>> DestRange.Value = SourceRange.Value
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>> "Dr. Schwartz" <(E-Mail Removed)> wrote in message news:0B9A9B2D-DBD4-4A05-80DD-(E-Mail Removed)...
>> > In Excel 2003 what do I need to change in this piece of code to only copy
>> > values?
>> >
>> > ThisWorkbook.Worksheets("source_sheet").Range(Cells(Jour_Rw, 1),
>> > Cells(Jour_Rw, 18)).copy
>> > Destination:=wb.Worksheets("target-sheet").Cells(FCDB_Rw, 1)
>> >
>> > An easy one I guess, but still...
>> >
>> > Thanks
>> > The Doctor

>
> --
>
> Dave Peterson


 
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
Excel2007: copying filtered table values, how can I copy ONLY thefiltered values AC Microsoft Excel Discussion 2 27th Nov 2009 09:27 PM
copy unique values into listbox, then modify sheet from these values Matthew Dyer Microsoft Excel Programming 4 28th Sep 2009 04:11 PM
Find matching values, copy/paste values as well as values in ColA ryguy7272 Microsoft Excel Programming 2 28th Sep 2009 06:20 AM
Copy/Paste how to avoid the copy of formula cells w/o calc values =?Utf-8?B?RGVubmlz?= Microsoft Excel Misc 10 2nd Mar 2006 10:47 PM
How do i compare values from two sheet and copy & paste if values match? =?Utf-8?B?cm96Yg==?= Microsoft Excel Programming 0 5th Mar 2004 12:06 AM


Features
 

Advertising
 

Newsgroups
 


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