Select next unique cell in visible row

pandagurl

New Member
Joined
Apr 13, 2021
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
I have a macro that selects the next unique value in a column, however there are hidden rows and it is also selecting cells that are hidden. How do I change the range to only active cells/rows?

Sub NextUnique()
' NextUnique Macro

Dim i As Integer
i = 0

Do
i = i + 1
If Cells(ActiveCell.Row + i, ActiveCell.Column).Value <> ActiveCell.Value Then
Cells(ActiveCell.Row + i, ActiveCell.Column).Select
Exit Do
End If
Loop
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try adding the red part as below.

If Cells(ActiveCell.Row + i, ActiveCell.Column).Value <> ActiveCell.Value And Rows(i + 1).Hidden = False Then
 
Upvote 0
Unfortunately that doesn't seem to work. It skips both hidden and unhidden cells and selects a random blank cell way down the page.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top