Nuke_It_Newport
New Member
- Joined
- Nov 17, 2020
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
Hey everyone-
I am attempting to perform the following:
I've worked on this for hours upon hours, and searched for a solution online.
Here's the code:
I'm not sure if I need to use a different method altogether to search for duplicates, or if I've made a syntax error. If there's a more efficient way to compare columns, such as using an array, please let me know. Eventually I may search multiple columns for matches.
Thanks for your help!!
I am attempting to perform the following:
- Loop through sheets 4 through 8 in a workbook.
- Find any cell values in column "A" that match sheet 1 column "A", and note the cell positions (for example, A6, A19, A32).
- Apply formatting to these cell positions in sheet 1 (for this example, A6, A19, A32).
Code:
Set rng = SrcWS.Range("A:A").Find(c.Value, , xlValues, xlWhole)
I've worked on this for hours upon hours, and searched for a solution online.
Here's the code:
Code:
Option Explicit
Sub DoesNotWork()
Dim i As Integer
Dim StartIndex As Integer
Dim EndIndex As Integer
Dim SrcTbl As ListObject 'Source Table
Dim DstTbl As ListObject 'Destination Table
Dim c As Range
Dim rng As Range
Dim adr As String
Dim SrcWS As Worksheet 'Source Worksheet
Dim DstWS As Worksheet 'Destination worksheet
Set DstWS = Sheets("Import")
StartIndex = Worksheets(4).Index
EndIndex = Worksheets(8).Index
If StartIndex > 0 And EndIndex > 0 And EndIndex > StartIndex Then
For i = StartIndex To EndIndex
Set SrcWS = Worksheets(i)
' **** THIS LINE IS THROWING ERROR... *****
Set rng = SrcWS.Range("A:A").Find(c.Value, , xlValues, xlWhole)
If Not rng Is Nothing Then
adr = rng.Address
With DstWS
c.Font.Color = RGB(51, 153, 51) 'Dark Green
c.Font.Bold = True
End With
Do
Set rng = SrcWS.Range("A:A").FindNext(rng)
Loop While rng.Address <> adr
End If
Next i
End If
End Sub
I'm not sure if I need to use a different method altogether to search for duplicates, or if I've made a syntax error. If there's a more efficient way to compare columns, such as using an array, please let me know. Eventually I may search multiple columns for matches.
Thanks for your help!!