MikeMcCollister
Board Regular
- Joined
- May 6, 2020
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
I have a budget spreadsheet that has a table in it. Over the years, I just kept the table to 999 rows. This was more rows that I ever needed and things worked well. In some of my VBA functions, I would statically set the columns for items that I would look for. As they are static, I don't have to do a set every time there is a recalculation. By using static on the ranges, I got significant performance improvement (i.e. a factor of 2 to 4). Here is a portion of what I have been doing:
I started to mess around with the table in the budget spreadsheet and I decided not to make the table 999 rows but make it as big as needs to be. That is, I will add a row whenever on is needed. However, this messes up my static columns. If the columns are statically defined and I add a row to the table, the range does not change even though I am using the name of the table and the column name (i.e. "MainChecking[Category]"). It appears to set the range to the number of rows at the time it is set. If I close the spreadsheet and open it again, then it works for this time.
Is there any way to specify a range of a table column and have it work the way that I want?
I know that I can probably revert back to making the table 999 rows but I don't know if I want to do that .
Thanks,
Mike
VBA Code:
Private Const gMainCheckingWorksheet As String = "Main Checking Sheet"
Private Const gMainCheckingColumnCategory As String = "MainChecking[Category]"
Private Const gMainCheckingColumnFilledDate As String = "MainChecking[Filled Date]"
Function BudgetLineItemDate(category As String) As Variant
Static columnCategory As Range
Static columnFilledDate As Range
' bunch of stuff removed
With Application.ThisWorkbook.Worksheets(gMainCheckingWorksheet)
If (columnCategory Is Nothing) Then
Set columnCategory = .Range(gMainCheckingColumnCategory)
End If
If (columnFilledDate Is Nothing) Then
Set columnFilledDate = .Range(gMainCheckingColumnFilledDate)
End If
End With
' bunch of stuff removed
End Function
I started to mess around with the table in the budget spreadsheet and I decided not to make the table 999 rows but make it as big as needs to be. That is, I will add a row whenever on is needed. However, this messes up my static columns. If the columns are statically defined and I add a row to the table, the range does not change even though I am using the name of the table and the column name (i.e. "MainChecking[Category]"). It appears to set the range to the number of rows at the time it is set. If I close the spreadsheet and open it again, then it works for this time.
Is there any way to specify a range of a table column and have it work the way that I want?
I know that I can probably revert back to making the table 999 rows but I don't know if I want to do that .
Thanks,
Mike