Find a character in a textstring

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to find a character (in my case the letter S) in a list of
textstrings,
and then return the textstrings containing "S" , as well as the two other
columns that correspond to it .

My columns are as follows

36359 LP 21227.78
36360 FLS 16218.75
36361 FS 14471.59
36362 FS 30109.59
36363 FS 7801.26
36364 FAP 29816.75
36365 FLS 16875

So if I wanted to search for "S" in column 2, I would return;

36360 FLS 16218.75
36361 FS 14471.59
36362 FS 30109.59
36363 FS 7801.26
36365 FLS 16875
 
Data/Filter/Autofilter. Click the drop arrow in column 2, select custom.
Then Show rows where column 2 "contains" S.
 
A VBA solution:

Sub x()
Dim rng2 As Range
Set rng2 = Sheets("sheet2").Range("A2")
With Sheets("Sheet1")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To lastrow
If InStr(1, .Cells(r, "B"), "S") <> 0 Then
.Cells(r, "A").Resize(, 3).Copy rng2
Set rng2 = rng2.Offset(1, 0)
End If
Next r
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top