Macro to find unique cell in column

gmodrow

New Member
Joined
Mar 26, 2012
Messages
7
Hi,
I'm looking for a quick macro that moves the cursor to the next cell in the current column that does not match the current cell's value.

The following code works but is VERY inefficient.
Code:
Sub MoveDown()Application.ScreenUpdating = False
    Do
        ActiveCell.Offset(1, 0).Select
    Loop Until ActiveCell <> ActiveCell.Offset(-1, 0)
Application.ScreenUpdating = True
End Sub

I had a macro that did this instantaneously but I lost it with a harddrive crash. Please help!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
this should work:


Code:
Sub unique()
application.screenupdating = false
Do Until ActiveCell.Value <> ActiveCell.Offset(1, 0).Value
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(1, 0).Select
End Sub
 
Upvote 0
This works at about the same speed as my current code. I'm working through about 200k lines of code and this takes a few seconds; the previous macro was literally instantaneous.

This moves the cell each time there is not a match. Can't you just determine what cell that is and then move the cursor to that?
 
Upvote 0
See if this is faster

Code:
Sub aTest()
    Dim r As Variant, dataRange As Range, i As Long
    
    Set dataRange = Range(ActiveCell, ActiveCell.EntireColumn.Cells(Rows.Count).End(xlUp))
    r = dataRange
    For i = 1 To dataRange.Rows.Count
        If r(i, 1) <> r(i + 1, 1) Then Exit For
    Next i
    Cells(i + ActiveCell.Row, ActiveCell.Column).Activate
End Sub

M.
 
Upvote 0
That's it! I remember the code now that I've seen it. And yes it moves perfectly (instantly).

Thanks Marcelo - very appreciated.
 
Upvote 0

Forum statistics

Threads
1,216,555
Messages
6,131,372
Members
449,646
Latest member
dwalls

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