[VBA] Exercises vol.2

Long time since my last post:)

Today it’s so cold outside, that I finally could write next VBA code for your exercies.

Check this out

Open Your Excel and write the following six headers

Date1/Date2/Name1/Name2/Result1/Result2

choose different data format for first column a other one for second column.

f,e 12.12.2017 in DATE1 and 12 dec 2017 in DATE2

Write some names or companies, that are the same by have some small differences between like Carrefour Ltd in Name1 and Carrefour in Name2

Copy this code and see the effect of this exercise.

Sub CompareData()

Dim i, j As Integer

i = 2
j = 2

Arkusz1.Cells(i, 4) = Split(CStr(UCase(Trim(Arkusz1.Cells(i, 3)))))

For i = 2 To 10

If CDate(Arkusz1.Cells(i, 1).Value) = _
CDate(Arkusz1.Cells(i, 2).Value) Then
Arkusz1.Cells(i, 5).Value = "ok"
Else: Arkusz1.Cells(i, 5) = "not ok"
End If

If Arkusz1.Cells(i, 3) = Arkusz1.Cells(i, 4) Then
Arkusz1.Cells(i, 6) = "ok"
Else: Arkusz1.Cells(i, 6) = "not ok"
End If

If Arkusz1.Cells(i, 5).Value = "not ok" Then
Arkusz1.Cells(i, 5).Select
With Selection.Font
.Color = vbRed
End With

End If
If Arkusz1.Cells(i, 6).Value = "not ok" Then
Arkusz1.Cells(i, 6).Select
With Selection.Font
.Color = vbRed
End With

End If
Next i

End Sub

There is a way to optimse this code, but I will introduce this method in some other post:)

have a nice evening!