236h Testcode

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Sub FindMatchingValues()

Dim wb1 As Workbook, wb2 As Workbook


Dim ws1 As Worksheet, ws2 As Worksheet

Set wb1 = ThisWorkbook ' set the first workbook as the active workbook
Set ws1 = wb1.Sheets("Sheet6") ' set the first worksheet

' open the second workbook


Set wb2 = Workbooks.Open("E:\MyData\2022-23\ADJUSTED CHALLAN\adjusted.xlsx")
Set ws2 = wb2.Sheets("Sheet1") ' set the second worksheet

' loop through the rows in the first worksheet


For i = 1 To ws1.Range("A" & Rows.Count).End(xlUp).Row
' loop through the rows in the second worksheet
For j = 1 To ws2.Range("A" & Rows.Count).End(xlUp).Row
' check if the value in column A of the first worksheet matches the value
in column A of the second worksheet
' and if the value in column D of the first worksheet matches the value in
column D of the second worksheet
If ws1.Cells(i, 1).Value = ws2.Cells(j, 1).Value And ws1.Cells(i, 4).Value
= ws2.Cells(j, 4).Value Then
' if the values match, copy the value from column L of the first
worksheet to column K of the second worksheet
ws2.Cells(j, 11).Value = ws1.Cells(i, 12).Value
' write "Adjusted" in column L of the first worksheet
ws1.Cells(i, 12).Value = "Adjusted"
End If
Next j
Next i

wb2.Close ' close the second workbook

End Sub

You might also like