Place the following In a module :
Option Explicit
Sub in_between_or_not()
Dim startrow As Integer
Dim endrow As Integer
Dim actualrow As Integer
Dim counting As Integer
startrow = 11
endrow = LastCell(Dates_for_bids).Row
actualrow = 11
For counting = startrow To endrow
If Date >= Range("B" & actualrow) And Date <= Range("C" & actualrow) Then
actualrow = actualrow + 1
Else
Rows(actualrow).EntireRow.Hidden = True
actualrow = actualrow + 1
End If
Next counting
End Sub
Sub show_everything()
Dim startrow As Integer
Dim endrow As Integer
Dim actualrow As Integer
Dim counting As Integer
startrow = 11
endrow = LastCell(Dates_for_bids).Row
actualrow = 11
For counting = startrow To endrow
If Rows(actualrow).Hidden = True Then
Rows(actualrow).EntireRow.Hidden = False
actualrow = actualrow + 1
Else
actualrow = actualrow + 1
End If
Next counting
End Sub
Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%
On Error Resume Next
With ws
LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With
Set LastCell = ws.Cells(LastRow&, LastCol%)
End Function
--- End For module
This Is the code For the form With one listbox on it
Option Explicit
Private Sub UserForm_activate()
Dim R As Integer
Dim rijteller As Integer
Dim pos As Integer
Dim MyList() As String
Dim i As Integer
Dim echte_laatste_rij As Integer
echte_laatste_rij = LastCell(Dates_for_bids).Row
in_between_or_not
rijteller = 11
For R = 11 To echte_laatste_rij
If Rows(rijteller).Hidden = True Then
rijteller = rijteller + 1
Else
i = i + 1
rijteller = rijteller + 1
End If
Next R
ReDim Preserve MyList(i, 3)
Application.ShowToolTips = True
With ListBox1
.ColumnCount = 3
.ColumnWidths = "2 cm ;2 cm;5 cm"
.ControlTipText = "Dates for bids ..."
.ListStyle = fmListStylePlain
.SpecialEffect = fmSpecialEffectFlat
End With
rijteller = 11
pos = 0
With ActiveSheet
For R = 0 To echte_laatste_rij - 10
If Rows(rijteller).Hidden = True Then
rijteller = rijteller + 1
Else
MyList(pos, 0) = .Range("B" & rijteller)
MyList(pos, 1) = .Range("C" & rijteller)
MyList(pos, 2) = .Range("D" & rijteller)
pos = pos + 1
rijteller = rijteller + 1
End If
Next R
End With
ListBox1.List = MyList
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
show_everything
Unload Me
End Sub
|