I am trying to develop a custom VBA function that manipulates ranges, namely to remove duplicate values from a list and place the list of unique values in a specific column of the worksheet. The reason I am using a custom function call is that I would like the unique values list to update anytime a new entry is made the original list.
I can get the code to work when I run it manually as a subroutine (e.g., running just the Sub RemoveDuplicateValues()
segment below). However, when it is called from the custom function through the workbook (e.g., by entering =ManageLists()
in a worksheet cell), the code exits without doing anything at the first instance of trying to use one of the Range methods, namely at the line NewList.Value2 = OriginalList.Value2
.
Function ManageLists() As Double
Call RemoveDuplicateValues
End Function
Sub RemoveDuplicateValues()
Dim OriginalList, NewList As Range
Set OriginalList = Worksheets("App 4 Input").Range("A4:A503")
Set NewList = Worksheets("Grazing Group Manure Calculator").Range("CG4:CG503")
NewList.Value2 = OriginalList.Value2
NewList.RemoveDuplicates Columns:=Array(1)
End Sub