Hi. I'm new to the world of Excel programming, so I hope I'm not being too simple here. I've Googled around for the answer to this and couldn't find a simple fix.
I've created some UDFs for a specific Excel file I'm working on. Here's the code:
Function QuantityWithExtras(quantity)
QuantityWithExtras = WorksheetFunction.RoundUp(quantity * (1 + ([extrapercentage] / 100)), 0)
Application.Volatile
End Function
Function ExtraQuantity(quantity)
ExtraQuantity = WorksheetFunction.RoundUp(quantity * [extrapercentage] / 100, 0)
Application.Volatile
End Function
Function IfNum(quantity)
If quantity = "" Then
IfNum = 0
Else
IfNum = quantity
End If
Application.Volatile
End Function
Sub SelectAndSort()
'
' SelectAndSort Macro
' Selects the appropriate range and sorts Z-A based on the "Open" column. This removes blank lines, allowing the menu to be pasted into Epicor.
'
' Keyboard Shortcut: Ctrl+t
'
Range("B7:M74").Select
ActiveWorkbook.Worksheets("EPICOR ENTRY").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("EPICOR ENTRY").Sort.SortFields.Add Key:=Range("B7" _
), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("EPICOR ENTRY").Sort
.SetRange Range("B7:M74")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A7:M74").Select
End Sub
When I open my file, everything works fine, and the cells using those UDFs update as they should. When I open another Excel file, though, the cells using the ExtraQuantity function return #VALUE, and I have to double-click on the cells and press ENTER to get them to calculate correctly again. I can save at this point and reopen and everything's fine, but it errors again as soon as I open another file. What should I add to my functions to keep this from happening? Thanks.
Bookmarks