Loukas Char
New Member
- Joined
- Dec 15, 2013
- Messages
- 22
Hello to everybody!
In an excel file with more than 40.000 rows (this might variate) and 50 columns, the code checks for specific strings in a specific area: going from the second row it checks from column C up to column G (or at least I think so), up to the last row (which is unknown because it is not stable). Then the rows which have at least one of the strings are copied/pasted, one below the other, to Sheet 2 up to column 50. Have a look at the code.
Sub findNcopy()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, fLoc As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells.Find("*", sh1.Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set rng = sh1.Range("B2:G" & lr)
For i = 2 To lr
For j = 2 To 7
With sh1
If InStr(.Cells(i, j), "serv") > 0 Or InStr(.Cells(i, j), "financ") > 0 Or InStr(.Cells(i, j), "component") > 0 _
Or InStr(.Cells(i, j), "part") > 0 Or InStr(.Cells(i, j), "maint") > 0 Or InStr(.Cells(i, j), "install") > 0 _
Or InStr(.Cells(i, j), "repair") > 0 Or InStr(.Cells(i, j), "refurb") > 0 Or InStr(.Cells(i, j), "overhaul") > 0 _
Or InStr(.Cells(i, j), "procur") > 0 Or InStr(.Cells(i, j), "purchas") > 0 Or InStr(.Cells(i, j), "support") > 0 _
Or InStr(.Cells(i, j), "provis") > 0 Or InStr(.Cells(i, j), "lease") > 0 Or InStr(.Cells(i, j), "outsourc") > 0 _
Or InStr(.Cells(i, j), "licens") > 0 Or InStr(.Cells(i, j), "solut") > 0 Or InStr(.Cells(i, j), "solv") > 0 _
Or InStr(.Cells(i, j), "consult") > 0 Or InStr(.Cells(i, j), "advic") > 0 Or InStr(.Cells(i, j), "optimiz") > 0 _
Or InStr(.Cells(i, j), "optimis") > 0 Or InStr(.Cells(i, j), "assist") > 0 Or InStr(.Cells(i, j), "analys") > 0 _
Or InStr(.Cells(i, j), "turnkey") > 0 Or InStr(.Cells(i, j), "deliver") > 0 Or InStr(.Cells(i, j), "design") > 0 _
Or InStr(.Cells(i, j), "develop") > 0 Or InStr(.Cells(i, j), "custom") > 0 Or InStr(.Cells(i, j), "personali") > 0 _
Or InStr(.Cells(i, j), "tailored") > 0 Or InStr(.Cells(i, j), "adjust") > 0 Or InStr(.Cells(i, j), "traini") > 0 _
Or InStr(.Cells(i, j), "courses") > 0 Or InStr(.Cells(i, j), "pre-sal") > 0 Or InStr(.Cells(i, j), "after-sal") > 0 _
Or InStr(.Cells(i, j), "pre sal") > 0 Or InStr(.Cells(i, j), "after sal") > 0 Then
sh1.Range("A" & i).Resize(1, 50).Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2)
Exit For
End If
End With
Next
Next
End Sub
I have 2 issues that I cannot resolve:
1. I cannot change the search area in order to search from column C up to column E for each line, from line 2 up to the last (which as said before is unknown but around 40.000). I tried to change the search area and the iterations but it doesn’t work.
2. When I use all these strings it crashes. Do you think I should reduce them somehow? Is there anything else I could do? Any suggestions?
If there is someone who could help I would much appreciate it.
Cheers,
Loukas
In an excel file with more than 40.000 rows (this might variate) and 50 columns, the code checks for specific strings in a specific area: going from the second row it checks from column C up to column G (or at least I think so), up to the last row (which is unknown because it is not stable). Then the rows which have at least one of the strings are copied/pasted, one below the other, to Sheet 2 up to column 50. Have a look at the code.
Sub findNcopy()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, fLoc As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells.Find("*", sh1.Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set rng = sh1.Range("B2:G" & lr)
For i = 2 To lr
For j = 2 To 7
With sh1
If InStr(.Cells(i, j), "serv") > 0 Or InStr(.Cells(i, j), "financ") > 0 Or InStr(.Cells(i, j), "component") > 0 _
Or InStr(.Cells(i, j), "part") > 0 Or InStr(.Cells(i, j), "maint") > 0 Or InStr(.Cells(i, j), "install") > 0 _
Or InStr(.Cells(i, j), "repair") > 0 Or InStr(.Cells(i, j), "refurb") > 0 Or InStr(.Cells(i, j), "overhaul") > 0 _
Or InStr(.Cells(i, j), "procur") > 0 Or InStr(.Cells(i, j), "purchas") > 0 Or InStr(.Cells(i, j), "support") > 0 _
Or InStr(.Cells(i, j), "provis") > 0 Or InStr(.Cells(i, j), "lease") > 0 Or InStr(.Cells(i, j), "outsourc") > 0 _
Or InStr(.Cells(i, j), "licens") > 0 Or InStr(.Cells(i, j), "solut") > 0 Or InStr(.Cells(i, j), "solv") > 0 _
Or InStr(.Cells(i, j), "consult") > 0 Or InStr(.Cells(i, j), "advic") > 0 Or InStr(.Cells(i, j), "optimiz") > 0 _
Or InStr(.Cells(i, j), "optimis") > 0 Or InStr(.Cells(i, j), "assist") > 0 Or InStr(.Cells(i, j), "analys") > 0 _
Or InStr(.Cells(i, j), "turnkey") > 0 Or InStr(.Cells(i, j), "deliver") > 0 Or InStr(.Cells(i, j), "design") > 0 _
Or InStr(.Cells(i, j), "develop") > 0 Or InStr(.Cells(i, j), "custom") > 0 Or InStr(.Cells(i, j), "personali") > 0 _
Or InStr(.Cells(i, j), "tailored") > 0 Or InStr(.Cells(i, j), "adjust") > 0 Or InStr(.Cells(i, j), "traini") > 0 _
Or InStr(.Cells(i, j), "courses") > 0 Or InStr(.Cells(i, j), "pre-sal") > 0 Or InStr(.Cells(i, j), "after-sal") > 0 _
Or InStr(.Cells(i, j), "pre sal") > 0 Or InStr(.Cells(i, j), "after sal") > 0 Then
sh1.Range("A" & i).Resize(1, 50).Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2)
Exit For
End If
End With
Next
Next
End Sub
I have 2 issues that I cannot resolve:
1. I cannot change the search area in order to search from column C up to column E for each line, from line 2 up to the last (which as said before is unknown but around 40.000). I tried to change the search area and the iterations but it doesn’t work.
2. When I use all these strings it crashes. Do you think I should reduce them somehow? Is there anything else I could do? Any suggestions?
If there is someone who could help I would much appreciate it.
Cheers,
Loukas