[COLOR="Blue"]Public[/COLOR] [COLOR="Blue"]Sub[/COLOR] demo()
[COLOR="Blue"]Dim[/COLOR] rngRow [COLOR="Blue"]As[/COLOR] Range
[COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] rngRow [COLOR="Blue"]In[/COLOR] Selection.SpecialCells(12).Rows
[COLOR="Blue"]Debug.Print[/COLOR] rngRow.Address
[COLOR="Blue"]Next[/COLOR] rngRow
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
Option Explicit
Option Compare Text
Sub VisibleLines()
Dim iRow As Long, iRows As Long
Dim Sh As Worksheet
Set Sh = ActiveSheet
iRows = Sh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For iRow = 1 To iRows
If Not Sh.Rows(iRow).Hidden = True Then
MsgBox iRow & " Not Hidden"
Else
MsgBox iRow & " Hidden"
End If
Next iRow
End Sub
[COLOR="Blue"]Public[/COLOR] [COLOR="Blue"]Sub[/COLOR] demo()
[COLOR="Blue"]Dim[/COLOR] rngRow [COLOR="Blue"]As[/COLOR] Range, rngPreviousRow [COLOR="Blue"]As[/COLOR] Range
[COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] rngRow [COLOR="Blue"]In[/COLOR] Selection.SpecialCells(12).Rows
[COLOR="Blue"]If[/COLOR] [COLOR="Blue"]Not[/COLOR] rngPreviousRow [COLOR="Blue"]Is[/COLOR] [COLOR="Blue"]Nothing[/COLOR] [COLOR="Blue"]Then[/COLOR]
[COLOR="Green"]'! compare the first cell in the row with the first cell in the previous visible row[/COLOR]
[COLOR="Green"]'! if they match then hide the row[/COLOR]
rngRow.Hidden = (rngRow.Resize(, 1).Value = rngPreviousRow.Resize(, 1).Value)
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
[COLOR="Blue"]Set[/COLOR] rngPreviousRow = rngRow
[COLOR="Blue"]Next[/COLOR] rngRow
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
Sub VisibleLines()
Dim iRow As Long, iRows As Long
Dim Sh As Worksheet
Dim vValue1 As Variant, iValue1Row As Long
Dim vValue2 As Variant, iValue2Row As Long
Dim bFirstRow As Boolean
Set Sh = ActiveSheet
bFirstRow = True
iRows = Sh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For iRow = 1 To iRows
If Not Sh.Rows(iRow).Hidden = True Then
If Not bFirstRow Then
vValue2 = Sh.Cells(iRow, 1).Value ' Add Value Two in this case column 1
iValue2Row = iRow ' Add row of second value
If vValue1 <> vValue2 Then ' Change for your test here
Sh.Rows.Address(ivalue1row).Hidden = True ' hide the first row
vValue1 = vValue2 ' Swap Values
iValue1Row = iValue2Row ' Swap Values
End If
Else
vValue1 = Sh.Cells(iRow, 1).Value ' Add Value one in this case column 1
iValue1Row = iRow ' Add row of first value
End If
Else
MsgBox iRow & " Hidden"
End If
Next iRow
End Sub
Call MyMacro()
ActiveCell.Offset(1, 0).Activate
Do Until Selection.EntireRow.Hidden = False
If Seletion.EntireRow.Hidden = True Then
ActiveCell.Offset(1, 0).Activate
End If
Loop
Sub VisibleData()Dim ColNum, EndCol, BegCol, BegRow As Integer
Dim EndRow As Long
ColNum = 2
EndRow = Cells(500000, ColNum).End(xlUp).Row
EndCol = 8
BegCol = 1
BegRow = 7
Range(Cells(BegRow, BegCol), Cells(EndRow, EndCol)).SpecialCells(xlCellTypeVisible).Select
End Sub