The code is hard to read but it appears you have a procedure MaxXfer within another procedure Worksheet_Change. That is not allowed.
How to run Excel VBA code upon change in cell value
I would like to execute my first Excel VBA code whenever selected cell values change. The Sub MaxXfer() works fine manually. I now would like it to execute when certain cell values change. Encountering "End If without block If" error.
Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range
' The variable KeyCells contains the cells that will ' cause an alert when they are changed. Set KeyCells = Range("I12:O12")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _ Is Nothing Then
' Place your code here.
```Sub MaxXfer()
Dim k As Long
Dim ResultCell As Range
Dim ChangingCell As Range
Dim TargetScore As Integer
TargetScore = -2000
For k = 9 To 15 Set ResultCell = Cells(65, k) Set ChangingCell = Cells(13, k) ResultCell.GoalSeek TargetScore, ChangingCell Next k
End Sub
Microsoft 365 and Office Development Other
Microsoft 365 and Office Excel For business Windows
Developer technologies VB
1 answer
Sort by: Most helpful
-
Tom van Stiphout 1,861 Reputation points MVP Volunteer Moderator
2024-01-20T20:18:26.1866667+00:00