Hello All,
I'm in need of some assistance. I have a sheet that has data in Columns U through AZ. I am attempting to search each row to find specific text. Once that text is found in a cell, I want to copy that cell value and paste it in the same row but in column BA. I have hodgepodge various things together from various articles. But I seem to be getting nowhere. Any help would be greatly appreciated.
I'm in need of some assistance. I have a sheet that has data in Columns U through AZ. I am attempting to search each row to find specific text. Once that text is found in a cell, I want to copy that cell value and paste it in the same row but in column BA. I have hodgepodge various things together from various articles. But I seem to be getting nowhere. Any help would be greatly appreciated.
Rich (BB code):
Sub SearchAndCopy
Dim ws As Worksheet
Dim searchValue As String
Dim lastRow As Long
Dim i As Long
Set ws = Worksheets("Sheet1") ' Set the worksheet where you want to perform the search
searchValue = "LNR" ' Set the search value
lastRow = ws.Cells(ws.Rows.Count, "U").End(xlUp).Row ' Find the last row with data in column U
For i = 2 To lastRow ' Loop through each row
If WorksheetFunction.CountIf(ws.Range("U" & i & ":AZ" & i), searchValue) > 0 Then 'Check if the search value is found in cells U2 to AZ1338
Set foundCell = ws.Rows(i).Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False ' Find the cell with the search value in the row
If Not foundCell Is Nothing Then
ws.Cells(i, "58").Value = foundCell.Value ' Copy the value to column BA in the same row
End If
End If
Next i
End Sub
Last edited by a moderator: