Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2008, 04:54 PM
Authorized User
 
Join Date: Mar 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jgrant
Default Copy Paste Dynamic Range

Hi, I am trying to set the values of one dynamic range to another but I keep getting a run-time error. Here is the code:

Private Sub CommandButton1_Click()
    Dim intCollectionsLastRow As Integer
    Dim intLastCollectionCopyRow As Integer

    intCollectionsLastRow = 10 'FindRow(Sheet17, 10)
    intLastCollectionCopyRow = 11 'FindRow(Sheet16, 10) - 1

    Dim rngSource As Range
    Dim rngDest As Range
    Dim strOne As String
    Dim strTwo As String

    strOne = "B10:N" + CStr(intLastCollectionCopyRow)
    strTwo = "B" + CStr(intCollectionsLastRow) + ":N" + CStr
    (intCollectionsLastRow - 10)
    Set rngSource = Range("strTwo")
    Sheet17.Range(rngSource).Value = Sheet16.Range("strOne").Value



End Sub

Can anybody tell me what I am doing wrong? I need to copy only values.

 
Old February 5th, 2008, 10:13 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

If your intention is to copy the entire range you can try this

    strOne = "B10:N" + CStr(intLastCollectionCopyRow)
    strTwo = "B" + CStr(intCollectionsLastRow) ' You need the starting range alone for copy
    Sheet16.Range(strOne).Copy Destination:=Sheet17.Range(strTwo )

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Copy Paste sridevi HTML Code Clinic 5 August 11th, 2007 05:09 AM
copy paste !!!!!!! dpkbahuguna Beginning VB 6 1 March 30th, 2007 10:06 AM
copy paste problem paul20091968 Excel VBA 4 November 20th, 2006 10:48 AM
Copy, Paste dpkbahuguna Beginning VB 6 1 October 26th, 2006 10:30 AM
Copy and append paste canmex Access 2 October 7th, 2003 01:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.