Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,955 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
Finally figured out how to write this UDF that calculates position in a range. problem is when the sheet is refreshed or a flash fill is done, then the UDF incorrectly makes all the values the same. since this is happening in a sheet, is there a way to make this work?
I am using this UDF to look at a column, find the string, make an array of the string with row and position, and return the position in the activecell.
Function GetArrayCount(StringRange As Range) As Long 'StringRange As Range, Seed As Range
Dim Ws As Worksheet
Dim lCounter As Long
Dim LastRow As Long
Dim CodWinCount As Long
Dim Seed As Long
Dim vArray() As Variant
Dim GetCount As Variant 'this is the common count
Dim GetRow As Variant 'this is the row value
Set Ws = ThisWorkbook.Sheets("ControlsDB")
LastRow = Ws.Cells(Ws.Rows.count, "A").End(xlUp).Row
Seed = Ws.Range("Seed").Value
CodWinCount = Seed - 1
With Ws
For lCounter = 2 To LastRow
If .Range("F" & lCounter) = SCODEWINDOW Then
CodWinCount = CodWinCount + 1
ReDim Preserve vArray(Seed To CodWinCount)
vArray(CodWinCount) = lCounter & " " & CodWinCount
End If
Next lCounter
End With
Application.EnableEvents = False
For lCounter = LBound(vArray) To UBound(vArray)
GetCount = Split(vArray(lCounter), " ")(1)
GetRow = Split(vArray(lCounter), " ")(0)
If ActiveCell.Row = GetRow Then
GetArrayCount = GetCount
Application.MoveAfterReturnDirection = False
Exit Function
'Stop
End If
Next lCounter
End Function