Hello Guys,
I have a custom function that I created to make naming batches of work much easier (it was base on a formula that I used in excel).
The issue I'm having with it is that if any changes happen within the sheet that the function is it will work with no problem, but if I'm working on a different sheet from the one that I have the function then it does not update.
I think I know what's causing the issue, yet do not know how to approach it.
I believe that the issue is base on "WorksheetFunction.Count"
I have a custom function that I created to make naming batches of work much easier (it was base on a formula that I used in excel).
The issue I'm having with it is that if any changes happen within the sheet that the function is it will work with no problem, but if I'm working on a different sheet from the one that I have the function then it does not update.
I think I know what's causing the issue, yet do not know how to approach it.
I believe that the issue is base on "WorksheetFunction.Count"
Code:
Option Explicit'This Function is to name batches base one AS400 Batch Naming Scheme
' For RBO CC batches start with a 6 follow by a letter (Example 6A)
' For Velocity CC batches start with a 7 follow by a letter (Example 7A)
' For EFT batches start with a "E" follow by a letter (Example EA)
' For Medicare batches start with a "M" follow by a letter (Example MA)
' For RDS batches start with a "S" follow by a letter (Example SA)
Function BatchName(FirstProduct As Range, CurrentProduct As Range, Optional StartBatch As String) As String
Application.Volatile
Dim Letter As String
Letter = Chr(64 + WorksheetFunction.Count(Range(CurrentProduct.Address))) 'FirstProduct.Address & ":" &
BatchName = ""
Select Case StartBatch
Case 7
If CurrentProduct <> "" Then BatchName = StartBatch & Letter
If Asc(Letter) > 90 Or Left(BatchName, 1) = StartBatch + 1 Then BatchName = StartBatch + 1 & Chr(64 + WorksheetFunction.Count(Range(FirstProduct.Address & ":" & CurrentProduct.Address)) - 26)
Case 60
If CurrentProduct <> "" Then BatchName = StartBatch + WorksheetFunction.Count(Range(FirstProduct.Address & ":" & CurrentProduct.Address)) - 1
Case Else
If CurrentProduct <> "" Then BatchName = StartBatch & Chr(64 + WorksheetFunction.Count(Range(CurrentProduct.Address))) 'Letter
End Select
'Application.Calculate
End Function