Consulting

Results 1 to 5 of 5

Thread: Paste Named Range

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    48
    Location

    Paste Named Range

    I'm using the below code to copy/paste range into a worksheet.

    I'm trying to modify the code so that it will paste the range items in Column ("A3") until ("A80") and then skips a column ("F") and continues entering the range items again in column ("G3") until ("G80"). Ditto for that column, skips column ("L") and continues entering range items in column ("M3") until ("M80")

    [VBA]Select Case FListboxMover.PosList.Value
    Case "TOP200"
    Range("Heading1").Copy Range("A1")
    Range("TOP201").Copy Range("A3")
    [/VBA]

    Thanks,

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    it will paste the range items in Column ("A3") until ("A80") and then skips a column ("F")
    Please clarify. Is the source a single column or block of cells? Do you mean A3:E80 then skip F etc.? Does the source have the same number of rows (3-80)?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I thought this should insert data in the green cells, but it enters thee data in Column A. Anyone got a reason why?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    I see what your saying but i think that there is no areas collection to be had unless the cells are not touching...thus the sourse data could be achieved with a clever range name then accessing the areas of touching cells. I find that a Excel bug personally.

    [VBA]Sub test()
    Dim Source As Range
    Dim Tgt As Range
    Dim i As Long
    Set Source = Sheets(1).Cells(1, 1).CurrentRegion
    With Sheets(2)
    Set Tgt = .Cells(3, 1)
    For i = 1 To 11 Step 2
    Set Tgt = Union(Tgt, Range(.Cells(3, i), .Cells(10, i)))
    Next
    Tgt.Interior.ColorIndex = 35
    'MsgBox Tgt.Address
    For i = 1 To Tgt.Areas.Count
    Tgt.Areas(i).Value = Source.Value '<<<<< here I see what you mean.
    Next i
    End With
    End Sub
    [/VBA]

  5. #5
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    Like this mdmackillop, but I still don't think I understand the original question.

    [VBA]Sub test2()
    Dim Source As Range
    Dim Tgt As Range
    Dim i As Long
    'Set Source = Sheets(1).Cells(1, 1).CurrentRegion
    With Sheets(2)
    Set Tgt = .Cells(3, 1)
    For i = 1 To 10 Step 2
    Set Tgt = Union(Tgt, Range(.Cells(3, i), .Cells(15, i)))
    Next
    Tgt.Interior.ColorIndex = 35
    'MsgBox Tgt.Address
    For i = 1 To Tgt.Areas.Count
    Tgt.Areas(i).Value = Range("Source").Areas(i).Value '<<<<< here I see what you mean.
    Next i
    End With
    End Sub
    [/VBA]

Posting Permissions

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