Sub copyT()
Dim wrfrom As Worksheet
Dim wrto As Worksheet
Dim lastrw As Long
Dim i As Integer
Dim rng As Range
Set wrfrom = Sheet1
Set wrto = Sheet5
lastrw = wrfrom.Cells(Rows.Count, 1).End(xlUp).Row
wrfrom.Select
For i = 2 To lastrw
Set rng = Union(Range(Cells(i, 1), Cells(i, 6)), Cells(i, 8), Range(Cells(i, 14), Cells(i, 15)))
If wrfrom.Cells(i, 13) = "T" Then
rng.Copy wrto.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
End Sub
Hello!
I'm trying to make a new macro for my workbook. My goal is if there is a criteria met "T" in the 13th column of my worksheet then copy the row but only specific cells of the row (1-6th, 8th and 14-15th) to a different workbook.
I created an Union range with the cells I need but sometimes when I run my macro it doesn't do anything and sometimes it does everything properly.
It's not necesarry to start the pasting from the first blank row because my wrto sheet where I'm pasting is only a header formatted as a table, so the pasting will always start from the 4th row but I couldn't figure out how to do it properly
Any ideas how to make this macro more stable and working?
Thanks in advance
Dim wrfrom As Worksheet
Dim wrto As Worksheet
Dim lastrw As Long
Dim i As Integer
Dim rng As Range
Set wrfrom = Sheet1
Set wrto = Sheet5
lastrw = wrfrom.Cells(Rows.Count, 1).End(xlUp).Row
wrfrom.Select
For i = 2 To lastrw
Set rng = Union(Range(Cells(i, 1), Cells(i, 6)), Cells(i, 8), Range(Cells(i, 14), Cells(i, 15)))
If wrfrom.Cells(i, 13) = "T" Then
rng.Copy wrto.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
End Sub
Hello!
I'm trying to make a new macro for my workbook. My goal is if there is a criteria met "T" in the 13th column of my worksheet then copy the row but only specific cells of the row (1-6th, 8th and 14-15th) to a different workbook.
I created an Union range with the cells I need but sometimes when I run my macro it doesn't do anything and sometimes it does everything properly.
It's not necesarry to start the pasting from the first blank row because my wrto sheet where I'm pasting is only a header formatted as a table, so the pasting will always start from the 4th row but I couldn't figure out how to do it properly
Any ideas how to make this macro more stable and working?
Thanks in advance