Hi, I have code that I use as a personal macro on my ribbon that lets you highlight a list of cells and it pastes this to another tab and removes duplicates so I can get a unique count:
However, I have to always then delete the tab that it creates. I'm wondering, can this be modified to just pop up a dialogue box that shows the unique count so I do is see the count and then click ok?
Thanks!
Code:
Sub List_Unique_Values()
'Create a list of unique values from the selected column
Dim rSelection As Range
Dim ws As Worksheet
Dim vArray() As Long
Dim i As Long
Dim iColCount As Long
'Check that a range is selected
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range first.", vbOKOnly, "List Unique Values Macro"
Exit Sub
End If
'Store the selected range
Set rSelection = Selection
'Add a new worksheet
Set ws = Worksheets.Add
'Copy/paste selection to the new sheet
rSelection.Copy
With ws.Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
'.PasteSpecial xlPasteValuesAndNumberFormats
End With
'Load array with column count
'For use when multiple columns are selected
iColCount = rSelection.Columns.Count
ReDim vArray(1 To iColCount)
For i = 1 To iColCount
vArray(i) = i
Next i
'Remove duplicates
ws.UsedRange.RemoveDuplicates Columns:=vArray(i - 1), Header:=xlGuess
'Remove blank cells
On Error Resume Next
ws.UsedRange.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlShiftUp
On Error GoTo 0
'Autofit column
ws.Columns("A").AutoFit
'Exit CutCopyMode
Application.CutCopyMode = False
End Sub
However, I have to always then delete the tab that it creates. I'm wondering, can this be modified to just pop up a dialogue box that shows the unique count so I do is see the count and then click ok?
Thanks!