Copying rows if criteria is met but only specific cells of the row

wlknspc7

New Member
Joined
May 12, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
What is the name of the destination workbook including the extension (xlsx, xlsm)?
 
Upvote 0
Maybe use
VBA Code:
If UCase(Trim(wrfrom.Cells(i, 13))) = "T" Then
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top