I have a spreadsheet with a list of different chemical species, things like methane, ethane, propane, etc. I have functions/calculations that will take that list, reference physical properties on another sheet, and give results to the user. There are different equations that can be used, so I have a series of radio buttons to select which "equation of state" to choose.
If someone changes the value in one of the input fields, I want the selected EOS to re-trigger, using the updated value. Right now, I can't seem to get that to work correctly. If I change which radio button is selected, the calculation re-triggers just fine. But not when I update one of the cells in question.
Here's the code I have. I couldn't get it to work with multiple cells, so I just picked one to start with. Still having problems.
Any suggestions you might have with regards to what I'm doing, apart from my actual question, are appreciated. This is something I would really hope I could set up for others to use as well, and not just me.
edit: I'll add that the VBA functions/calcs put the answer in a specific cell on a worksheet. The equations are not built into the spreadsheet, so when one of the entry cells changes, the function needs to be recalculated. Below, I just have one function added at the moment, 'zViral'.
As always, I appreciate you experts here. Thank you for what you do for all of us!
Thanks!!
Matt
If someone changes the value in one of the input fields, I want the selected EOS to re-trigger, using the updated value. Right now, I can't seem to get that to work correctly. If I change which radio button is selected, the calculation re-triggers just fine. But not when I update one of the cells in question.
Here's the code I have. I couldn't get it to work with multiple cells, so I just picked one to start with. Still having problems.
Any suggestions you might have with regards to what I'm doing, apart from my actual question, are appreciated. This is something I would really hope I could set up for others to use as well, and not just me.
edit: I'll add that the VBA functions/calcs put the answer in a specific cell on a worksheet. The equations are not built into the spreadsheet, so when one of the entry cells changes, the function needs to be recalculated. Below, I just have one function added at the moment, 'zViral'.
Code:
'When I click a different radio button, this just retriggers the calc. Seems to work just fine.
Sub CheckOptions() 'I have this in Module1
Select Case TypeName(Application.Caller)
Case "Error" 'I added this because after I added the Application.Caller routine I kept getting VBA errors
Debug.Print "Oops"
Application.Calculate
Case "obIdeal"
Debug.Print "You clicked Ideal Gas"
Application.Calculate
Case "obViral"
Debug.Print "You clicked Viral"
zViral
Application.Calculate
Case "obSRK"
Debug.Print "You clicked SRK"
Application.Calculate
Case "obPR"
Debug.Print "You clicked PR"
Application.Calculate
End Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range) 'This is in the code section for the worksheet, should it be a Public sub?
Dim WatchCells As Range
'Cell Names to watch:
' _Comp.T
' _Comp.P
' _Comp.F
' _Comp.Atm.P
' Set WatchCells = Range("_Comp.T", "_Comp.P", "_Comp.F", "_Comp.Atm.P")
Set WatchCells = Range("$D$3")
If Not Application.Intersect(WatchCells, Range(Target.Address)) Is Nothing Then
' MsgBox "Cell " & Target.Address & " has changed."
CheckOptions
End If
End Sub
As always, I appreciate you experts here. Thank you for what you do for all of us!
Thanks!!
Matt