Consulting

Results 1 to 4 of 4

Thread: VBA - Paste to First Empty Cell in Range

  1. #1

    VBA - Paste to First Empty Cell in Range

    I am working on a sheet that needs to be able to pull data & paste it into the first empty row of a defined range (C6:H16). I would typically use a count from the bottom, however, as there is data below where I need to paste it hasn't been working.

    The idea is to find all related objects, select the related row, and move it to the empty range.

    I am quite new to Excel, so bear with me. Here's the section I'm working on and what I have so far:

    PHP Code:
    With Sheet1
         
    For Each FoundCell In rng
                FoundCell
    .Select            
               Range
    (Cells(Selection.Row3), Cells(Selection.Row8)).Select            
                Selection
    .Copy
                
    ~(Find range and paste to next empty row in Range C6:H16)
         
    Next
    End With 

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With Sheet1
         For Each FoundCell In Rng
            Set tgt = .Cells(17, "H").End(xlUp)(2)
            FoundCell.Resize(, 6).Copy tgt
         Next
    End With
    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
    Quote Originally Posted by mdmackillop View Post
    With Sheet1
         For Each FoundCell In Rng
            Set tgt = .Cells(17, "H").End(xlUp)(2)
            FoundCell.Resize(, 6).Copy tgt
         Next
    End With
    This works great. Is there a way to move the selection's values only (without reformatting the destination?)

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With Sheet1 
        For Each FoundCell In Rng 
            Set tgt = .Cells(17, "H").End(xlUp)(2) 
            FoundCell.Resize(, 6).Copy
            tgt.PasteSpecial xlValues 
        Next 
    End With
    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'

Posting Permissions

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