VBA: Find given words in column A with start and end position.
Sheet: input1 has Name in column A and their details in column B
Sheet: input2 has Names and words.
If Names and words found in sheet input1 then Sheet: input2 will look like Sheet: output
Sub Demo1() Dim Rg(1) As Range, V, R&, A$, W, P& Set Rg(0) = Sheets("Input1").UsedRange.Columns(2) Application.ScreenUpdating = False With Sheets("input2").UsedRange .Offset(1, 1).ClearContents V = .Columns(1).Value2 For R = 2 To UBound(V) If Not IsEmpty(V(R, 1)) Then Set Rg(1) = Rg(0).Find(V(R, 1), , xlValues, xlPart) If Not Rg(1) Is Nothing Then A = Rg(1).Address Do W = Application.Match(Rg(1)(1, 0), .Rows(1), 0) If IsNumeric(W) Then P = InStr(Rg(1), V(R, 1)) .Cells(R, W).Value2 = V(R, 1) & ", " & P & "-" & P - 1 + Len(V(R, 1)) End If Set Rg(1) = Rg(0).FindNext(Rg(1)) Loop Until Rg(1).Address = A End If End If Next End With Application.ScreenUpdating = True Erase Rg End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Re: VBA: Find given words with start and end position
If the search input is more than once in the line then it's giving only the first searched output.
Can the above VBA code be modified and let me get the output in the "same cell/same search term with a comma"?
Bookmarks