Consulting

Results 1 to 3 of 3

Thread: Paste and End(xlRight)

  1. #1
    VBAX Regular
    Joined
    Oct 2018
    Posts
    43
    Location

    Paste and End(xlRight)

    Hello Everyone,

    I am trying to paste some data, in another sheet, in the last column.

    Basically I would like this code:

    wsWar.Range(Cells(2, 6), Cells(50, y - 5)).Copy wsWar2.Cells(1, 82).End(xlRight).Offset(0,1)
    But of course, this one is not correct...
    Some of you would have ideas?

    Thanks a lot in advance for your time
    Edmond

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    The destination part says

    wsWar2.Cells(1, 82).End(xlRight).Offset(0,1)
    From CD1 (1,82)

    go to the first non-blank cell or the last cell (XFD1) and then

    go one more columns

    SO it depends of whether there are any non-blank cells after CD1

    Now if you to append another column to a block of data, I usually use something like

    Option Explicit
    Sub Macro1()
        With ActiveSheet
            .Range("A1:E10").Value = 123
            MsgBox .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1).Address
            .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1) = 987
        End With
    End Sub
    i.e. from far right, go left to first non-blank cell, and then right one column
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Oct 2018
    Posts
    43
    Location
    Excellent! Great idea!

    If someone is interested, I paste below the code I used to copy/paste in another worksheet, to the last used cell in the first row:

    With wsWar2
    
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    
    End With
    
     wsWar.Range(Cells(2, 6), Cells(50, y - 5)).Copy wsWar2.Cells(1, LastCol).Offset(0, 1)
    Thanks a lot Paul!
    Last edited by Paul_Hossler; 12-04-2018 at 02:00 PM. Reason: added CR
    Edmond

Posting Permissions

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