Code
There are several ways to match the values of an Excel file. (. Find, Match, Arrays, Dictionary, Collection, Autofilter, Loop, Excel Formula)
If the spreadsheet has a lot of data the methods that use arrays are faster, but the autofilter is also fast and easier to understand. Therefore, this will be used. The interaction between the VBA and the spreadsheet must be minimized and this reference hard-working.
Statements
Dim ws As Worksheet
'Worksheet de index 1 ou inserir o "NOME_entre_aspas"
Set ws = ThisWorkbook.Sheets(1)
Dim j As Long, i As Long, LastRow As Long
Dim VisibleRange As Range
Dim MyArray As Variant
ReDim MyArray(0 To 1000)
j = 0
Leading
Data = Format(Now, "dd-mm")
'Loop da Coluna 2 (B) até C(3)
With ws
'Última Linha da coluna A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To 3
'AutoFiltro
.Range(.Cells(1, i), .Cells(1, i)).AutoFilter Field:=i, Criteria1:=Data
'Cria range com as células visíveis após Filtrar
On Error Resume Next
Set VisibleRange = .Range(.Cells(2, 1), .Cells(LastRow, 1)).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not VisibleRange Is Nothing Then
'Loop nas células visíveis após aplicação do AutoFiltro
For Each Cell In VisibleRange
MyArray(j) = Cell
j = j + 1
Next
End If
'"zera" o autofiltro, mostrando todos dados filtrados
If .FilterMode Then
.ShowAllData
End If
Next i
'Redimensiona Array para quantidade de elementos correto
If j > 0 Then
ReDim Preserve MyArray(0 To j - 1)
'Loop em cada elemento da Array para criar String
For j = LBound(MyArray) To UBound(MyArray)
txt = txt & MyArray(j) & vbCrLf
Next j
MsgBox txt
Else
MsgBox "Nenhuma data encontrada."
End If
End With
Dice
Assuming the values as follows:
If you are from another, format in the spreadsheet or code.
Upshot
Yes it is possible! You can use
msgbox
for this! Just generate code logic in vba to make this check. Remembering dates with "01-01", using a dash-
are not standard in Excel, but if you are using conditional formatting, ok! Have you done any code to generate this validation? Could you post?– Evert
@Evis I am using dates in excel standard, I put here just to exemplify. In the case I still could not do anything, I looked at some VBA tutorials but it is very complicated. I did not create the logic to generate this validation. Only in my head. The logic is: within an array of values (columns and excel rows) I will fetch today’s date. After taking the line reference that is dated today, I want to take the cell of the name of the person who has the corresponding date. And then display people’s names on msgbox.
– João Neto