Consulting

Results 1 to 5 of 5

Thread: range copy with paste

  1. #1

    range copy with paste

    OK, I admit I read somewhere to avoid copy/paste. I want to copy a row of data from one worksheet to another. First I copy the header row. But it copies only the data and I want things like column width copied as well. I can't seem to find the correct parameter to use to make it copy everything.

    wsNewM.rows(1) = wsOldM.rows(1)

    This was my first attempt and it moved nothing. So I added the ".Value" as such:

    wsNewM.rows(1).Value = wsOldM.rows(1).Value

    This copies the data but nothing else. (wsNewM and wsOldM are both worksheets and properly declared.)

    I also notice that VBE religiously changes my capitalization of "Rows" to "rows". Why? I thought this was some kind of object readability issue.

    Thanks

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    Sub a()
    wsOldM.Rows(1).Copy wsNewM.Rows(1)
    End Sub

  3. #3
    Thank you Patel. The code does indeed perform as expected.

    I'm curious because I thought this used the clipboard (because of ".Copy"). Does this construction avoid the clipboard? Does this mean that the clipboard is used only when the "Paste" or "PasteSpecial" is used?

    Thanks again.

  4. #4
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    I think my code uses the clipboard for copying, but erases it after execution.
    You can have the same result with
    Sub a() 
        wsOldM.Rows(1).Copy 
        wsNewM.Rows(1) .paste
       Application.CutCopyMode = False
    End Sub

  5. #5
    Thanks again. I'm definitely trying to avoid using the clipboard.

Posting Permissions

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