NateO said:
This should also work, note however, as MyRng becomes very large, setting the union becomes bollox slow:
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> Dude_Yer_Gittin_A_Del()
<SPAN style="color:darkblue">Dim</SPAN> Uni <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">New</SPAN> Collection, cl <SPAN style="color:darkblue">As</SPAN> Range, myRng <SPAN style="color:darkblue">As</SPAN> Range
Application.ScreenUpdating = <SPAN style="color:darkblue">False</SPAN>
<SPAN style="color:darkblue">On</SPAN> <SPAN style="color:darkblue">Error</SPAN> <SPAN style="color:darkblue">Resume</SPAN> <SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">For</SPAN> <SPAN style="color:darkblue">Each</SPAN> cl <SPAN style="color:darkblue">In</SPAN> Range([c1], [c65536].End(3))
Uni.Add cl.Value, <SPAN style="color:darkblue">CStr</SPAN>(cl.Value)
<SPAN style="color:darkblue">If</SPAN> Err.Number <> 0 <SPAN style="color:darkblue">Then</SPAN>
Err.Clear
<SPAN style="color:darkblue">If</SPAN> myRng <SPAN style="color:darkblue">Is</SPAN> <SPAN style="color:darkblue">Nothing</SPAN> <SPAN style="color:darkblue">Then</SPAN> <SPAN style="color:darkblue">Set</SPAN> myRng = cl Else _
<SPAN style="color:darkblue">Set</SPAN> myRng = Union(cl, myRng)
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Next</SPAN> cl
<SPAN style="color:darkblue">Set</SPAN> Uni = <SPAN style="color:darkblue">Nothing</SPAN>
myRng.EntireRow.Delete
Application.ScreenUpdating = <SPAN style="color:darkblue">True</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
I didn't necessarily want to write this as such, but a different line of logic, which seemed much better, wasn't working as I expected it to...
I've recently had my pc go through an upgrade on its operating system here at work and this code (above) used to work wonderfully before the upgrade to WinXP but not the code can't run because I get a compile error; "Can't find project or library".
The code breaks at "[A1]" in the code below.
For Each Al In Range([A1], [A65536].End(3))
Does anyone know a work around or the library I'd need to help run this code?
Here is my complete code (I've made the adjustment for Nate's code to look in column A instead of C)...
Private Sub Sort_Click()
Application.ScreenUpdating = False
Range("F2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*1"
Range("F2").Copy
Range("F15000").Select
Range("F2:F15000").Select
Range("F15000").Activate
Range("F2:F15000").Select
Range("F15000").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("F:F").Select
Application.CutCopyMode = False
Selection.ClearContents
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("B2").Select
ActiveCell.FormulaR1C1 = "0"
Range("C2").Select
ActiveCell.FormulaR1C1 = "0"
Range("D2").Select
ActiveCell.FormulaR1C1 = "0"
Range("E2").Select
ActiveCell.FormulaR1C1 = "0"
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "SKU_CD"
Range("B1").Select
ActiveCell.FormulaR1C1 = "SKU_DESC"
Range("C1").Select
ActiveCell.FormulaR1C1 = "SKU_ANALYSIS"
Range("D1").Select
ActiveCell.FormulaR1C1 = "NVTY_LOCATION"
Dim Uni As New Collection, Al As Range, myRng As Range
On Error Resume Next
For Each Al In Range([A1], [A65536].End(3))
Uni.Add Al.Value, CStr(Al.Value)
If Err.Number <> 0 Then
Err.Clear
If myRng Is Nothing Then Set myRng = Al Else _
Set myRng = Union(Al, myRng)
End If
Next Al
Set Uni = Nothing
myRng.EntireRow.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
ActiveCell.FormulaR1C1 = "0"
Range("B1").Select
ActiveCell.FormulaR1C1 = "0"
Range("C1").Select
ActiveCell.FormulaR1C1 = "0"
Range("D1").Select
ActiveCell.FormulaR1C1 = "0"
Range("E1").Select
ActiveCell.FormulaR1C1 = "0"
Range("F1").Select
Columns("A:E").Copy
Sheets("Catalogue").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Sheets("Sku Importer").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A1").Select
Application.ScreenUpdating = True
End Sub
~Trag
