Consulting

Results 1 to 3 of 3

Thread: Solved: Copy and Paste to new row/column IF values exist in paste

  1. #1

    Solved: Copy and Paste to new row/column IF values exist in paste

    A novice to VBA -- I have exhausted my few resources (two beginner texts!) and now resorting to the experts.

    I am want to copy and paste a range of cell to another to sheet (which I know how to do), however IF the there are values in the targeted paste cells, than paste to a new column or the next empty column to the right.

    Is this difficult? Can anyone help?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Welcome to VBAX

    [VBA]Option Explicit

    Sub Test()
    Dim r As Range
    Dim cel As Range
    Dim tgt As Range

    Set r = Sheets(1).Range("A1:A10")

    For Each cel In r
    Set tgt = Sheets(2).Cells(cel.Row, Columns.Count).End(xlToLeft)
    If tgt <> "" Then Set tgt = tgt.Offset(, 1)
    cel.Copy tgt
    Next
    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
    Amazing!!

    Thank you kindly.

Posting Permissions

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