andre30331
New Member
- Joined
- May 14, 2014
- Messages
- 29
Hello,
I have code that when I select column B the script looks through column B for duplicate values among unique numerical strings of data. When a duplicate is located the code should delete the entire row without scrambling or re-sorting the data set and copy the final result of the entire sheet inclusive of columns A:E to a new sheet.
I have code that when I select column B the script looks through column B for duplicate values among unique numerical strings of data. When a duplicate is located the code should delete the entire row without scrambling or re-sorting the data set and copy the final result of the entire sheet inclusive of columns A:E to a new sheet.
- The first issue I am having is instead of coping the final results and the data from columns A thru E onto the new sheet it only copies the value of column B to all other columns on the new sheet.Column B data rereated in cloumn A,C,D,& E
- The second issues is I would simply like to run the code and it search through column B without having to actually select column B for the code to work.
Code:
Option Explicit
Sub List_Unique_Values()
Dim rSelection As Range
Dim ws As Worksheet
Dim vArray() As Long
Dim i As Long
Dim iColCount As Long
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range first.", vbOKOnly, "List Unique Values Macro"
Exit Sub
End If
Set rSelection = Selection
Set ws = Worksheets.Add
rSelection.Copy
With ws.Range("A:E")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
'.PasteSpecial xlPasteValuesAndNumberFormats
End With
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
On Error Resume Next
ws.UsedRange.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlShiftUp
On Error GoTo 0
ws.Columns("A").AutoFit
Application.CutCopyMode = False
End Sub