Re: Conditionally copy selected cells in rows depending on cell contents.
The confusing
There's no reason for this code raise the error.
Code
Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet, rng As Range, r As Range, LastR As Range
Set ws1 = Workbooks("ST_Production Schedule.xls").Sheets("SCHED")
Set ws2 = Workbooks("GT&TT Trial.xlsm").Sheets("Sheet1")
Set rng = ws1.Range("b4", ws1.Range("b" & Rows.Count).End(xlUp))
For Each r In rng
If r.Value Like "*GT*" Then
Set LastR = ws2.Cells.SpecialCells(11).Offset(1).EntireRow
LastR.Range("a1").Value = r.EntireRow.Range("f1").Value
' ..........↑ Copy to ↑ Copy from
LastR.Range("b1").Value = r.EntireRow.Range("g1").Value
' add like the example above
End If
Next
Set ws1 = Nothing
Set ws2 = Nothing
Set rng = Nothing
End Sub
Display More