Olá, segue a solução para o seu problema. qualquer duvida pode mandar DM no insta @thiagoalves.ah, ficarei feliz em ajuda-lo.
Sub GetDados()
Dim tabDdsMedico As Range
Dim tabDdsPaciente As Range
Dim iProcesso As String
Dim iDate As Date
Dim i As Long, j As Long
Set tabDdsMedico = Sheet2.Range("A1").CurrentRegion.Offset(1)
Set tabDdsPaciente = Sheet1.Range("A1").CurrentRegion.Offset(1)
With tabDdsMedico
Set tabDdsMedico = .Resize(.Rows.Count - 1)
End With
With tabDdsPaciente
Set tabDdsPaciente = .Resize(.Rows.Count - 1)
End With
On Error GoTo IfError
With tabDdsPaciente
For i = 1 To .Rows.Count
iProcesso = CStr(.Cells(i, 1))
iDate = CDate(.Cells(i, 2))
For j = 1 To tabDdsMedico.Rows.Count
If iProcesso = CStr(tabDdsMedico.Cells(j, 1)) And _
iDate >= CDate(tabDdsMedico.Cells(j, 2)) Then
.Cells(i, 3) = tabDdsMedico.Cells(j, 3)
.Cells(i, 4) = tabDdsMedico.Cells(j, 4)
Exit For
End If
Next
Next
End With
MsgBox "Processo concluido com sucesso!", vbInformation, "Concluido"
Exit Sub
IfError:
MsgBox "Ocorreu um erro durante o processo de atualização" & _
vbCrLf & "Reveja a macro de atualização", vbCritical
End Sub