My solution will run when you select the worksheet if you copy this code to the worksheet object you want to run it against. It assumes that your name 'Range' is just an integer value that equals the number of rows you want to insert the named 'BinTest' formula starting at cell A37:
Private Sub Worksheet_Activate()
Dim name1, name2, varRange, c, rowCount
' Assign named formulas to variables...
name1 = ActiveWorkbook.Names("BinTest")
name2 = ActiveWorkbook.Names("Range")
' Get value of named 'Range' workbook object- strip off the '=' sign...
rowCount = Int(Mid(name2, 2, 5))
' Ensure Excel worksheet row limit isn't exceeded...
If rowCount > 65500 Then
MsgBox "Your value for 'Range' exceeds the row limit for EXCEL worksheets."
Exit Sub
End If
' Define the range of cells to insert the named "BinTest" formula
' Start at cell A37 & add the value of name "Range" to the row to include in range of cells...
varRange = ActiveSheet.Cells(37, 1).Address & ":" & Cells((37 + rowCount), 1).Address
' Insert the "BinTest" formula in each cell of the range...
For Each c In Range(varRange)
c.Formula = name1
Next
End Sub
Hope this helps,
theDude
Bookmarks