Writing Sheet events in Excel
Writing Sheet events in Excel
(OP)
Writing sheet events in Excel is very simple. Just right click in sheet tab and select view code. Select work sheet from objects section and apropriate event from the declarations section. Write necessary code. Thats all. You can do a lot with this feature. You can change the back ground color of cell with a single click in a cell or can change the back color when the value of cell falls with in a certain limit for a warning in your calculations.
RE: Writing Sheet events in Excel
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.ScreenUpdating = False
On Error GoTo ExitSub
Select Case Target.Name.Name
Case Is = "Dia"
[DiaM] = [Dia] * 2.54
Case Is = "DiaM"
[Dia] = [DiaM] / 2.54
Case Is = "H"
[HM] = [H] * 2.54
Case Is = "HM"
[H] = [HM] / 2.54
Case Is = "Temp"
[TempM] = ([Temp] - 32) * (5 / 9)
Case Is = "TempM"
[Temp] = ([TempM] * (9 / 5)) + 32
End Select
ExitSub:
End Sub
RE: Writing Sheet events in Excel
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Example Worksheet Event Code to convert between Metric and English units in input cells
' CAUTION delete the "t" in front of the subroutine name.
Application.ScreenUpdating = False
Application.EnableEvents = False'<<<<<CHANGE
On Error GoTo ExitSub
Select Case Target.Name.Name
Case Is = "MdotE"
[MdotM] = [MdotE] / 2.204623 'lbm/hr >> kg/hr
Case Is = "MdotM"
[MdotE] = [MdotM] * 2.204623 'kg/hr >> lbm/hr
Case Is = "DiaE"
[DiaM] = [DiaE] * 2.54 'inches >> cm
Case Is = "DiaM"
[DiaE] = [DiaM] / 2.54 'cm >> inches
Case Is = "PressE"
[PressM] = [PressE] * 6894.757 'psia >> Pascals
Case Is = "PressM"
[PressE] = [PressM] / 6894.757 'Pa >> psia
Case Is = "TempE"
[TempM] = ([TempE] - 32) * (5 / 9) 'F >> C
Case Is = "TempM"
[TempE] = ([TempM] * (9 / 5)) + 32 'C >> F
End Select
ExitSub:
Application.EnableEvents = True '<<<<<CHANGE
End Sub