Thanks so much. I'd found some of those workarounds on the web, but couldn't figure them out. In fact, I've really only just begun tampering with VBA. Can you tell me what the difference is between slotting in your code into my existing one and creating/running a new worksheet object module? Or whether using either one of the codes you posted may be better since when I tried them out, they both produced the same result?
This has your second code slotted in. When I swap the three lines with the one-liner from your first post, it produced the same result only with a slight delay in the other calculations.
Private Sub Worksheet_Change(ByVal target As Range)
Dim rInt As Range
Dim cell As Range
Application.EnableEvents = False
If Not Intersect(target, Range("J11:J45")) Is Nothing Then Range("J11:J45") = "=IF(E11="""","""",SUM(E11:I11))"
Application.EnableEvents = True
Set rInt = Intersect(target, Range("E11:E45"))
If Not rInt Is Nothing Then
On Error GoTo Error
Application.EnableEvents = False
For Each cell In rInt
If VarType(cell.Value2) = vbDouble Then
cell.Value = cell.Value / 30 * 15
End If
Next cell
End If
Set rInt = Intersect(target, Range("F11:F45"))
If Not rInt Is Nothing Then
On Error GoTo Error
Application.EnableEvents = False
For Each cell In rInt
If VarType(cell.Value2) = vbDouble Then
cell.Value = cell.Value / 100 * 40
End If
Next cell
End If
Set rInt = Intersect(target, Range("G11:G45"))
If Not rInt Is Nothing Then
On Error GoTo Error
Application.EnableEvents = False
For Each cell In rInt
If VarType(cell.Value2) = vbDouble Then
cell.Value = cell.Value / 100 * 20
End If
Next cell
End If
Set rInt = Intersect(target, Range("H11:H45"))
If Not rInt Is Nothing Then
On Error GoTo Error
Application.EnableEvents = False
For Each cell In rInt
If VarType(cell.Value2) = vbDouble Then
cell.Value = cell.Value / 10
End If
Next cell
End If
Set rInt = Intersect(target, Range("I11:I45"))
If Not rInt Is Nothing Then
On Error GoTo Error
Application.EnableEvents = False
For Each cell In rInt
If VarType(cell.Value2) = vbDouble Then
cell.Value = cell.Value / 100 * 15
End If
Next cell
End If
Error:
Application.EnableEvents = True
End Sub
Bookmarks