Copy row if 14-17 digis is exact..

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
hello,

I need to copy row to new sheet based on column M with long number and I like to copy it only if 14-17 digit are 2005, 2025, 2026 and couple more.
my code is:

Code:
Dim cell2 As Range
Dim lastRow2 As Long, j As Long


lastRow2 = Range("N" & Rows.Count).End(xlUp).Row
j = 2


For Each cell2 In Sheets(1).Range("N1:N" & lastRow2)
    If cell2.Value = "TRANSFER" And [B].............................[/B] Then
        cell2.EntireRow.Copy Sheets("Next").Cells(j, 1)
        j = j + 1
    End If

I need Your help!

Best Regards
W.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi

There are many ways, try this one:

Code:
Sub Test()
Dim cell2 As Range
Dim lastRow2 As Long, j As Long


lastRow2 = Range("N" & Rows.Count).End(xlUp).Row
j = 2


For Each cell2 In Sheets(1).Range("N1:N" & lastRow2)
    If cell2.Value = "TRANSFER" Then
        Select Case Mid(cell2.Offset(0, -1).Value, 14, 4)
            Case "2005", "2025", "2026"
                cell2.EntireRow.Copy Sheets("Next").Cells(j, 1)
                j = j + 1
        End Select
    End If
Next cell2
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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