ASadStudent
New Member
- Joined
- Oct 26, 2022
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hello everyone, the code I am using right now copies data from 1 excel file to another excel file. These files are called "omzet" and "maandafsluiting" and the sheets are just called Sheet1.
The way the macro works is that it looks at the B row on both excel files and if the name on both files is the same it copies the data it has (Which is in the N row of the "omzet" file) to the place where the data needs to go (Which is in the F row of the "maandafsluiting" file).
My question was if it is possible to make the product name in the "omzet" file red if it can't find a similar name in the other file.
The reason I need this function is so that if a new product gets sold that isn't in the "maandafsluiting" file yet then I can easily find it and add it. I can also find out if some names aren't perfectly the same so I can change that as well.
Beneath here is my macro and printscreens of what both excel files look like.
Thanks a lot for helping me solve this problem!
My macro:
Omzet
Maand afsluiting:
The way the macro works is that it looks at the B row on both excel files and if the name on both files is the same it copies the data it has (Which is in the N row of the "omzet" file) to the place where the data needs to go (Which is in the F row of the "maandafsluiting" file).
My question was if it is possible to make the product name in the "omzet" file red if it can't find a similar name in the other file.
The reason I need this function is so that if a new product gets sold that isn't in the "maandafsluiting" file yet then I can easily find it and add it. I can also find out if some names aren't perfectly the same so I can change that as well.
Beneath here is my macro and printscreens of what both excel files look like.
Thanks a lot for helping me solve this problem!
My macro:
VBA Code:
Sub Kijken()
Dim omzet As Worksheet: Set omzet = Workbooks.Item("Omzet").Sheets("Sheet1")
Dim Maandafsluiting As Worksheet: Set Maandafsluiting = Workbooks.Item("Maandafsluiting").Sheets(1)
Dim data As Variant, lr As Long, d As Object, key As String, rw As Long
lr = omzet.Cells(Rows.Count, 2).End(3).Row
data = omzet.Cells(1, 1).Resize(lr, 14).Value
Set d = CreateObject("Scripting.Dictionary")
For rw = LBound(data) To UBound(data)
If data(rw, 14) <> 0 Then
key = data(rw, 2)
If Not d.exists(key) Then
d(key) = data(rw, 14)
End If
End If
Next rw
lr = Maandafsluiting.Cells(Rows.Count, 2).End(3).Row
data = Maandafsluiting.Cells(1, 1).Resize(lr, 6).Formula
For rw = LBound(data) To UBound(data)
key = data(rw, 2)
If d.exists(key) Then
data(rw, 6) = d(key)
End If
Next rw
Maandafsluiting.Cells(1, 6).Resize(UBound(data)).Formula = Application.Index(data, 0, 6)
End Sub
Omzet
Maand afsluiting: