What I want my code to do: there is a sheet called "DB" which has data taken from table. I have "XML" WorkSheet which has data taken from XML. I want to take a column name "FName" from "DB" sheet and search for the same column name "FName" in "XML" sheet. If column name matches, then take the corresponding value from the "DB" sheet and Compare with the "XML" Sheet. I have another sheet "results" in the same workbook. I have taken the column names from "DB" sheet and pasted transpose (column in row wise). I have to do below scenario:
1. if column names match in both the sheets:
- Search for Value match for the corresponding column name in both the sheets. If the value match, In "results" sheet I have to write "Match" or "NO Match" in the column next to the row which has the column name "FName".
2.if column names DOES NOT match in both the sheets:
- In "results" sheet I have to write "NO Matching COLUMN" in the column next to the row which has the column name "FName".
currently, in this code, I wanted to parse through each column in "DB" sheets and search for that column. But I am getting "Application-Defined or Object-Defined Error" .
Please let me know how to achieve the above scenarios:
Dim FindString As Range
Dim Rng As Range
Dim i, j As Integer
Dim finalcol As Long
Worksheets("DB").Select
finalcol = Worksheets("DB").Cells(1, Application.Columns.Count).End(x1toleft).column
On Error Resume Next
For i = 1 To finalcol
FindString = Cells(1, i).Value
If Trim(FindString) <> "" Then
With Sheets("xml").Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
Next i
On Error GoTo 0
End Sub