Consulting

Results 1 to 4 of 4

Thread: can't paste content

  1. #1

    can't paste content

    [VBA]
    Sub test()
    Dim i As Integer
    Dim Header As Variant
    Application.ScreenUpdating = False

    'write array values
    Header = Array("Franchise Code", "Account", "Name", "1-15 Days", "16-25 Days", "26-30 Days", "31-40 Days" _
    , "41-45 Days", "46-60 Days", "61-90 Days", "91-120 Days", "Over 120 Days", "Total", "Terms")

    Range("A:A").End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).EntireRow.Copy
    'create headers on Licensing tab
    For i = 1 To UBound(Header)
    Worksheets("Licensing").Cells(1, i).Value = Header(i)
    Next i

    'paste copied content
    Worksheets("Licensing").Paste (Range("A2"))

    End Sub
    [/VBA]

    Everything goes well untill i get to "'paste copied content
    " part. Necessary content is copied, headers on Licensing tab are created, when i get to paste part it's saying: "Run time error 1004 / Paste method of worksheet class failed.", i'm totally stuck, help file didn't help me. Any suggestions?

    Thanks.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You're trying to paste an entire column into a smaller area.
    Try
    [VBA]
    Sub test()
    Dim i As Integer
    Dim Header As Variant
    Application.ScreenUpdating = False

    'write array values
    Header = Array("Franchise Code", "Account", "Name", "1-15 Days", "16-25 Days", "26-30 Days", "31-40 Days" _
    , "41-45 Days", "46-60 Days", "61-90 Days", "91-120 Days", "Over 120 Days", "Total", "Terms")

    'create headers on Licensing tab

    Worksheets("Licensing").Cells(1, 1).Resize(, UBound(Header) + 1).Value = Header

    'paste copied content
    Range(Range("A2"), Range("A2").End(xlDown)).EntireRow.Copy Worksheets("Licensing").Range("A2")

    End Sub

    [/VBA]
    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
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim i As Integer
    Dim Header As Variant
    Application.ScreenUpdating = False

    'write array values
    Header = Array("Franchise Code", "Account", "Name", "1-15 Days", "16-25 Days", "26-30 Days", "31-40 Days" _
    , "41-45 Days", "46-60 Days", "61-90 Days", "91-120 Days", "Over 120 Days", "Total", "Terms")

    Range("A:A").End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).EntireRow.Copy Worksheets("Licensing").Range("A2")
    'create headers on Licensing tab
    For i = 1 To UBound(Header)
    Worksheets("Licensing").Cells(1, i).Value = Header(i)
    Next i
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thank you that worked perfectly!

Posting Permissions

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