Hi there,

I'm new to the forum and almost to vba in Excel too.

I had a discipline in the university about vba but I don't remember anything at all.

I manage to do this macro by myself but it's not working. It stop in the first "if".

What I need the macro to do is the following:
- Read Table1
- Find Date1 and Hour1 (in two different cells)
- Compare Date1 with Date2 from the Table2
- If Date1 = Date2 then compare Hour1 with Hour2.1 and Hour2.2
- If Hour1 is between Hour2.1 and Hour2.2 then copy a ValueX from Table2 to Table1
- Repeat cycle until the ValueX column from Table1 is all filled

MACRO:

Sub Match_Prod_Stop()

Dim a As Integer, b As Integer, c As Integer
Dim data_maple As Date
Dim hora_maple As Date
Dim SKU As Long
Dim LastRow As Long

LastRow = ActiveSheet.UsedRange.Rows.Count

For a = 1 To LastRow

ActiveWorkbook.Sheets("Dados Maple").Activate
Data_prod = ActiveWorkbook.Sheets("Dados Maple").Cells(a + 3, 4)
hora_maple = ActiveWorkbook.Sheets("Dados Maple").Cells(a + 3, 6)
b = 1

Do While SKU = "0"
ActiveWorkbook.Sheets("Produções").Activate

If data_maple = ActiveWorkbook.Sheets("Produções").Cells(b + 1, 4) Then
If hora_maple > ActiveWorkbook.Sheets("Produções").Cells(b + 1, 13) And hora_maple < ActiveWorkbook.Sheets("Produções").Cells(b + 1, 14) Then

SKU = ActiveWorkbook.Sheets("Produções").Cells(b + 1, 2)
End If
End If
b = b + 1
Loop
ActiveWorkbook.Sheets("Dados Maple").Cells(a + 3, 10) = SKU
a = a + 1
Next
ActiveWorkbook.Save
End Sub