I've got some Excel spreadsheets that are hitting the database pretty hard (100+ queries against the general ledger table... yikes!). Refreshing just the sheet I'm on (SHIFT+F9) is helpful in some spreadsheets, but I wanted a way to refresh just the selected cells. I'm came up with the following code, placed in the ThisWorkbook object:
Dim currentSelection As String
Private Sub Workbook_Open()
Application.OnKey "+^{F9}", "ThisWorkbook.RecalculateSelection"
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
currentSelection = Target.Address
End Sub
Private Sub RecalculateSelection()
Range(currentSelection).Calculate
End Sub
If possible, I'd like to make this more portable, such as storing it in an XLA file and loading it as an Excel addin. Is this possible with the method I'm using? Is there a better way to achieve this?