Consulting

Results 1 to 3 of 3

Thread: VBA, copy, clear cell, 2007 excel

  1. #1

    VBA, copy, clear cell, 2007 excel

    Hello,

    I'm stumped on how to write code for following


    1. How do I clear cell contents after its copied?


    The code below works by looking in Col C. if words exist than copy next 2 adjacent cells & add with cell In Col c. I would like those adjacent cells content cleared.

    Sub testY()
    'Looks for word "x" then copy cell info of next 2 cells into the 1st cell
    
    
    Set MyRng = Range(Cells(2, "C"), Cells(Rows.Count, "C").End(xlUp))
    
    
    For Each Cell In MyRng
        If Cell.Value = "Init" _
        Or Cell.Value = "Tr" Then
        Cell.Value = Cell.Value & "_" & Cell.Offset(0, 1) & "_" & Cell.Offset(0, 2).Value
            End If
        Next
    End Sub
    Thanks,
    weenie
    Last edited by mdmackillop; 07-14-2017 at 03:04 AM. Reason: Code tags added

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Sub testY()
    'Looks for word "x" then copy cell info of next 2 cells into the 1st cell
    
    
    Set MyRng = Range(Cells(2, "C"), Cells(Rows.Count, "C").End(xlUp))
    
    
    For Each Cell In MyRng
    If Cell.Value = "Init" _
    Or Cell.Value = "Tr" Then
    Cell.Value = Cell.Value & "_" & Cell.Offset(0, 1) & "_" & Cell.Offset(0, 2).Value
    Cell.offset(,1).resize(,2).clearcontents
    End If
    Next
    End Sub
    (untested).
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thank you so much. It works & saves time.

    Thanks,
    weenie

Posting Permissions

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