I have the following code which successfully copies cells B, E and F to cells B, C, D in sheet 2 after I match a string in another cell. The problem is that it copies the cell and not only just the value inside it (I don't need borders, colour etc).
Another issue I have is that while it will copy the data to the next free row in Column B, it won't look for the next free row according to column C and D.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim thisrow As Long
Dim lr As Long
If Target.Column = 7 Then
thisrow = Target.Row
If Target.Value = "FAULTY" Then
lr = Sheets("sheet2").Range("B" & Rows.Count).End(xlUp).Row + 1
Range("B" & ActiveCell.Row).Copy Sheets("sheet2").Range("B" & lr)
Range("D" & ActiveCell.Row).Copy Sheets("sheet2").Range("C" & lr)
Range("F" & ActiveCell.Row).Copy Sheets("sheet2").Range("D" & lr)
End If
End If
End Sub
Range(..).Value = Range(..).Value
insteadRange(..).Copy
– Dmitry Pavliv.select
needs to be activated in order to use pastespecial, and select is also know as a bad programming practice stackoverflow.com/questions/10714251/… – Richbut .select needs to be activated in order to use pastespecial,
- why do you think so?Range("A1").Copy
and thenSheets("sheet2").Range("B2").PasteSpecial xlPasteValues
– Dmitry Pavliv