PDA

View Full Version : [SOLVED] VBA, copy, clear cell, 2007 excel



weenie
07-13-2017, 07:32 PM
Hello,

I'm stumped on how to write code for following



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

p45cal
07-14-2017, 02:17 AM
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).

weenie
07-14-2017, 11:49 AM
Thank you so much. It works & saves time.

Thanks,
weenie