Answer the question
In order to leave comments, you need to log in
How to filter a table in Excel in VB?
There is a table in Excel of the form
Text | Text | Text | Start date | End date|
Text | Text | Text | Start date | End date|
Text | Text | Text | Start date | End date|
Text | Text | Text | Start date | End date|
There is also some cell (for example, $A$1) separate from the table, in which there is some
date start and end dates.
If the cell is empty, then all rows should be displayed.
I hope I explained clearly. I know that the answer is easy, I myself have never written macros in VB, so I ask for advice or help with a piece of code.
Answer the question
In order to leave comments, you need to log in
Sub macros()
Dim i, cell_start, cell_end As Integer
Dim cell_x As Date
i = 1
cell_start = 4 ''' номер ячейки с начальной датой '''
cell_end = 5 ''' номер ячейки с конечной датой '''
cell_x = Cells(21, 4) ''' ячейка с контрольной датой '''
While (Cells(i, cell_start) <> "")
Rows(i).Select
If (Cells(i, cell_start) <= cell_x) And (Cells(i, cell_end) >= cell_x) Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
i = i + 1
Wend
End Sub
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question