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
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,235
Office Version
  1. 365
Platform
  1. Windows
What's wrong with the current code?

It looks fine to me.:)
 

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
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>
 

kishorkhanal

Active Member
Joined
Mar 23, 2006
Messages
434
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,481
Messages
5,601,918
Members
414,482
Latest member
morkar

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
Top