Code to get unique values

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
I want unique values from DailyJobs worksheet cells B4:B2199 to FixErrors worksheet cells B4:B2199. Please suggest a better option or correct the following code.

Sub CopyUniques()
Worksheets("DailyJobs").Columns("B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Worksheets("FixErrors").Range("B4"), Unique:=True
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What's wrong with the current code?

It looks fine to me.:)
 
Upvote 0
Try this:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
<o:p></o:p>
Rich (BB code):
Rich (BB code):
Sub CopyUniques()<o:p></o:p>
Dim Limit As Long, c As Long, i As Long<o:p></o:p>
Dim Jobs As Worksheet, iErrors As Worksheet<o:p></o:p>
Set Jobs = Sheets("DailyJobs")<o:p></o:p>
Set iErrors = Sheets("FixErrors")<o:p></o:p>
Limit = Jobs.Cells(Rows.Count, 2).End(xlUp).Row<o:p></o:p>
i = 1<o:p></o:p>
For c = Limit To 1 Step -1<o:p></o:p>
    If WorksheetFunction.CountIf(Jobs.Columns(2), Jobs.Cells(c, 2)) = 1 Then<o:p></o:p>
        Jobs.Rows(c).Copy Destination:=iErrors.Rows(i)<o:p></o:p>
        i = i + 1<o:p></o:p>
    End If<o:p></o:p>
Next c<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
 
Upvote 0
Try this:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
<o:p></o:p>
Rich (BB code):
Rich (BB code):
Sub CopyUniques()<o:p></o:p>
Dim Limit As Long, c As Long, i As Long<o:p></o:p>
Dim Jobs As Worksheet, iErrors As Worksheet<o:p></o:p>
Set Jobs = Sheets("DailyJobs")<o:p></o:p>
Set iErrors = Sheets("FixErrors")<o:p></o:p>
Limit = Jobs.Cells(Rows.Count, 2).End(xlUp).Row<o:p></o:p>
i = 1<o:p></o:p>
For c = Limit To 1 Step -1<o:p></o:p>
    If WorksheetFunction.CountIf(Jobs.Columns(2), Jobs.Cells(c, 2)) = 1 Then<o:p></o:p>
        Jobs.Rows(c).Copy Destination:=iErrors.Rows(i)<o:p></o:p>
        i = i + 1<o:p></o:p>
    End If<o:p></o:p>
Next c<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>

When I run this code, my excel file freezes. Any suggestions please?
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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