Hello,
I have an excel spreadsheet with duplicate/similar names in it (in the thousands). I need to be able to find the duplicates/similar names by taking a substring from the original string value starting in cell (1,1) and comparing it to all other string values in the worksheet. This means that I am not searching just for one string. I am searching first to see if there are duplicates for the string located in cell (1,1), then searching for duplicates to cell (2,2) and so on through the entire worksheet. Right now my code only words for finding all the dupes for a specific string defined by me. How do I iterate through the entire spreadsheet (changing the value I am searching on each time?)
Code I have already.
Sub FindAndExecute()
Dim i As Integer
Dim LastRow As Long
Dim OriginalRange, SearchRange As Range
Dim Sh As Worksheet
Dim Loc As Range
Dim Search, SubSearch As String
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
OriginalRange = ActiveSheet.UsedRange
SubSearch = Cells(11, 3).Value
For Each Sh In ThisWorkbook.Worksheets
With Sh.UsedRange
Set Loc = .Cells.Find(What:=Mid(SubSearch, 1, 8), SearchDirection:=xlNext)
If Not Loc Is Nothing Then
Do Until Loc Is Nothing
Loc.Value = "Answered!"
Set Loc = .FindNext(Loc)
Loop
End If
End With
Set Loc = Nothing
Next
End Sub
I have an excel spreadsheet with duplicate/similar names in it (in the thousands). I need to be able to find the duplicates/similar names by taking a substring from the original string value starting in cell (1,1) and comparing it to all other string values in the worksheet. This means that I am not searching just for one string. I am searching first to see if there are duplicates for the string located in cell (1,1), then searching for duplicates to cell (2,2) and so on through the entire worksheet. Right now my code only words for finding all the dupes for a specific string defined by me. How do I iterate through the entire spreadsheet (changing the value I am searching on each time?)
Code I have already.
Sub FindAndExecute()
Dim i As Integer
Dim LastRow As Long
Dim OriginalRange, SearchRange As Range
Dim Sh As Worksheet
Dim Loc As Range
Dim Search, SubSearch As String
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
OriginalRange = ActiveSheet.UsedRange
SubSearch = Cells(11, 3).Value
For Each Sh In ThisWorkbook.Worksheets
With Sh.UsedRange
Set Loc = .Cells.Find(What:=Mid(SubSearch, 1, 8), SearchDirection:=xlNext)
If Not Loc Is Nothing Then
Do Until Loc Is Nothing
Loc.Value = "Answered!"
Set Loc = .FindNext(Loc)
Loop
End If
End With
Set Loc = Nothing
Next
End Sub