+ Reply to Thread
Results 1 to 5 of 5

copy but don't overlay

Hybrid View

  1. #1
    Registered User
    Join Date
    06-08-2005
    Posts
    67

    copy but don't overlay

    Is there a way via a macro to copy the values in a range of cells to another range of cells, but if there is anything in the destination range of cells, do not overlay with the values you are copying from?

    Consolidating would work, except I would need my destination cell range to be one of the consolidation cell ranges.

  2. #2
    Registered User
    Join Date
    09-16-2004
    Location
    Virginia
    Posts
    46
    Dim rng1 As Range
    Dim rng2 As Range
    Set rng1 = Range("A1:B50") ' Your copy range
    Set rng2 = Range("C1:D50") ' Your paste range
    For Each x In rng2.Cells
       If x.Value <> "" Then Exit Sub
    Next x
    rng1.Copy
    rng2.PasteSpecial xlPasteAll
    HTH
    Tom Stock
    Office version: MSO 2002 SP3
    OS: Windows XP Pro
    Hardware: IBM Thinkpad T41

  3. #3
    Registered User
    Join Date
    06-08-2005
    Posts
    67
    Thanks, but it did not work.

    I have attached an example spreadsheet with the macro in it. Maybe I am missing something. I want to be able to copy cells E1:G3 to A1:C3 but not overlay what is already in cell A1:C1.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-16-2004
    Location
    Virginia
    Posts
    46
        Dim rng1 As Range
        Dim rng2 As Range
        Set rng1 = Range("e1:g3") ' Your copy range
        Set rng2 = Range("a1:c3") ' Your paste range
        r1 = rng1.Rows.Count
        c1 = rng1.Columns.Count
    
        For i = 1 To r1
            For j = 1 To c1
                If rng2.Cells(i, j) = "" Then
                    rng2.Cells(i, j) = rng1.Cells(i, j)
                End If
            Next j
        Next i
    That work for you? I thought if your paste range contained ANYTHING you didn't want to paste anything. If you are just filling in, this should work.

  5. #5
    Registered User
    Join Date
    06-08-2005
    Posts
    67
    Got it....many thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1