P
Phil Hageman
Excel 2000, code located in the worksheet code object.
Testing the first of three parameter cases in this
worksheet code; columns P1013 (data entry cells),
V10:V13 (data entry cells), U19:U30 (data entry cells),
and column X19:X30 (code results cells):
Entering the value 100 in cell P10, and the value 50 in
cell V10 sets up a case for entries in U19:U30. After
entering the value 75 in cell U19, pressing enter, the
code should calculate the value 50 for cell X19. Instead,
there is no value entered in cell X19 (it is blank on
screen) and the cursor moves on to cell U20. No error
messages.
Entering the value 75 in AD19 results in #Div/0! in
cell AG19, result should be 50.
Entering the value 75 in AM19 results in #Div/0! in
cell AP19, result should be 50.
Entering the value 75 in AV19 results in #Div/0! in
cell AY19, result should be 50.
Can someone help me correct this?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As range)
Dim nRow As Long
Dim nRow1 As Long
Dim dV As Double
Dim dP As Double
Dim rng As range
Set rng = Intersect(range("U:U, AD:AD, AM:AM, AV:AV"), _
range("19:30, 51:62, 83:94"))
With Target
If .Count > 1 Then Exit Sub
If NotIntersect(.Cells, rng) Is Nothing Then
nRow1 = Int((.row - 19) / 32)
nRow = Int(.Column - 21) / 9
dV = range("V10").Offset _
(nRow + 32 * nRow1, 0).Value
dP = range("P10").Offset _
(nRow + 32 * nRow1, 0).Value
Application.EnableEvents = False
.Offset(0, 3).Value = (.Value - dV) / (dP - dV)
Application.EnableEvents = True
End If
End With
End Sub
Testing the first of three parameter cases in this
worksheet code; columns P1013 (data entry cells),
V10:V13 (data entry cells), U19:U30 (data entry cells),
and column X19:X30 (code results cells):
Entering the value 100 in cell P10, and the value 50 in
cell V10 sets up a case for entries in U19:U30. After
entering the value 75 in cell U19, pressing enter, the
code should calculate the value 50 for cell X19. Instead,
there is no value entered in cell X19 (it is blank on
screen) and the cursor moves on to cell U20. No error
messages.
Entering the value 75 in AD19 results in #Div/0! in
cell AG19, result should be 50.
Entering the value 75 in AM19 results in #Div/0! in
cell AP19, result should be 50.
Entering the value 75 in AV19 results in #Div/0! in
cell AY19, result should be 50.
Can someone help me correct this?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As range)
Dim nRow As Long
Dim nRow1 As Long
Dim dV As Double
Dim dP As Double
Dim rng As range
Set rng = Intersect(range("U:U, AD:AD, AM:AM, AV:AV"), _
range("19:30, 51:62, 83:94"))
With Target
If .Count > 1 Then Exit Sub
If NotIntersect(.Cells, rng) Is Nothing Then
nRow1 = Int((.row - 19) / 32)
nRow = Int(.Column - 21) / 9
dV = range("V10").Offset _
(nRow + 32 * nRow1, 0).Value
dP = range("P10").Offset _
(nRow + 32 * nRow1, 0).Value
Application.EnableEvents = False
.Offset(0, 3).Value = (.Value - dV) / (dP - dV)
Application.EnableEvents = True
End If
End With
End Sub