I inherited this UDF.
What it does is to look at the cells in a column that contains 4-digit numbers and for each cell it returns the duplicated number twice. For example if a cell contains 2454 it would return 44 and if a cell contains 0999 it would return 99 and if the cell contains something like 1234 it would return a blank. (Strange, I know but that's the requirement.)Code:Public Function GetDouble(v As String) As String Dim tmpArr(Limit - 1) As String If Len(v) = Limit Then tmpArr(0) = Mid(v, 1, 1) tmpArr(1) = Mid(v, 2, 1) tmpArr(2) = Mid(v, 3, 1) tmpArr(3) = Mid(v, 4, 1) For i = 0 To Limit - 1 - 1 For j = i + 1 To Limit - 1 If tmpArr(i) = tmpArr(j) Then GetDouble = tmpArr(i) & tmpArr(j) Exit Function End If Next j Next i End If GetDouble = "" End Function
The UDF fires any time Excel calculates, and because the worksheet contains 7,000+ rows it takes a very long time. I know that if I set Application.Calculation to xlCalculationManual that that wouldn't happen, but is there any way to avoid having to do that? Would replacing the UDF with an Excel formula help? If so what would that formula be?




Reply With Quote