advanced filter, goto next line(record)
Hi Pierre
the code below should do what you want, i set up a userform with 3
textboxes a combobox and three buttons (1 to filter and a Next and
Previous button) and used this code to filter data held in the range
A1:C20 and populate the textboxes.
Option Explicit
Dim MyRng As Range
Private Sub CmdFilter()
With Sheets("DataDGA")
Range("A1:C20").Select
Selection.AutoFilter Field:=1, Criteria1:=ComboBox1.Value
Set MyRng = Cells.SpecialCells(xlCellTypeVisible).Cells(1)
Do
Set MyRng = MyRng.Offset(1, 0)
Loop While MyRng.EntireRow.Hidden = True
Call CellsToTextBoxes
End With
End Sub
Private Sub CmdPrev_Click()
Do
Set MyRng = MyRng.Offset(-1, 0)
Loop While MyRng.EntireRow.Hidden = True
Call CellsToTextBoxes
End Sub
Private Sub CmdNext_Click()
Do
Set MyRng = MyRng.Offset(1, 0)
Loop While MyRng.EntireRow.Hidden = True
Call CellsToTextBoxes
End Sub
Sub CellsToTextBoxes()
TextBox1.Value = MyRng.Value
TextBox2.Value = MyRng.Offset(0, 1).Value
TextBox3.Value = MyRng.Offset(0, 1).Value
End Sub
Hope this helps you out
Steven
|