View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default After made a filter selection, hide to select visible rows based on the registration in the visible cell related to the visible row above

Hi Johan,

Am Mon, 30 Dec 2019 06:35:51 -0800 (PST) schrieb JS SL:

The selection is oke and then I've got visible rows with 'data-B' and a lot of rows with 'x'. None of the rows with 'x' (when there is a visible row below with also an 'x' in column N) is hidden by the macro.

I see that it isn't work because in column N is also other data registered then 'Data-B' and 'x'. When I delete this data then it works oke.
Strange.... because I can't delete this data. This is the data in the rows that are the hidden rows (those are the ones that are not selected in the filtering).


try:

Sub Test()
Dim rngC As Range
Dim LRow As Long, n As Long
Dim varRows() As Variant

With ActiveSheet
LRow = .Cells(.Rows.Count, "N").End(xlUp).Row
With .Range("N1")
.AutoFilter Field:=1, Criteria1:="=data-B", _
Operator:=xlOr, Criteria2:="=x"
End With
For Each rngC In .Range("N2:N" & LRow).SpecialCells(xlCellTypeVisible)
ReDim Preserve varRows(n)
varRows(n) = rngC.Row
n = n + 1
Next
For n = LBound(varRows) To UBound(varRows) - 1
If .Cells(varRows(n), "N") = "x" And .Cells(varRows(n + 1), "N") < "data-B" Then
.Rows(varRows(n)).Hidden = True
End If
Next
If .Cells(LRow, "N") = "x" Then .Rows(LRow).Hidden = True
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016