Todd
The best solution I thought of was to flush vertices into a range, and then flush these range values ββinto a variant array. As you said, For Next (for 10,000 cells in my test) took a few seconds. So I created a function that returns the top of the cell into which it entered. The code below is basically a function that copies the used range of the sheet that you pass to it, and then enters the function described above into each cell of the used range of the copied sheet. Then it transfers and unloads them into an array of options.
It only takes a second or about 10,000 cells. I don't know if this is useful, but it was an interesting question. If this is useful, you can create a separate function for each property or pass the desired property or return four arrays (?) ...
Option Explicit Option Private Module Sub test() Dim tester As Variant tester = GetCellProperties(ThisWorkbook.Worksheets(1)) MsgBox tester(LBound(tester), LBound(tester, 2)) MsgBox tester(UBound(tester), UBound(tester, 2)) End Sub Function GetCellProperties(wsSourceWorksheet As Excel.Worksheet) As Variant Dim wsTemp As Excel.Worksheet Dim rngCopyOfUsedRange As Excel.Range Dim i As Long Application.ScreenUpdating = False Application.Calculation = xlCalculationManual wsSourceWorksheet.Copy after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count) Set wsTemp = ActiveSheet Set rngCopyOfUsedRange = wsTemp.UsedRange rngCopyOfUsedRange.Formula = "=CellTop()" wsTemp.Calculate GetCellProperties = Application.WorksheetFunction.Transpose(rngCopyOfUsedRange) Application.DisplayAlerts = False wsTemp.Delete Application.DisplayAlerts = True Set wsTemp = Nothing Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Function Function CellTop() CellTop = Application.Caller.Top End Function
Todd
In response to your request for non-standard UDF, I can only offer a solution close to where you started. This takes 10 times more for 10,000 cells. The difference is that your back to the loop through the cells.
I am pushing my personal envelope here, so maybe someone will have access to it without a special UDF.
Function GetCellProperties2(wsSourceWorksheet As Excel.Worksheet) As Variant Dim wsTemp As Excel.Worksheet Dim rngCopyOfUsedRange As Excel.Range Dim i As Long Application.ScreenUpdating = False Application.Calculation = xlCalculationManual wsSourceWorksheet.Copy after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count) Set wsTemp = ActiveSheet Set rngCopyOfUsedRange = wsTemp.UsedRange With rngCopyOfUsedRange For i = 1 To .Cells.Count .Cells(i).Value = wsSourceWorksheet.UsedRange.Cells(i).Top Next i End With GetCellProperties2 = Application.WorksheetFunction.Transpose(rngCopyOfUsedRange) Application.DisplayAlerts = False wsTemp.Delete Application.DisplayAlerts = True Set wsTemp = Nothing Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Function
source share