The behavior I'm getting is so bizarre. My sheet has an area called Setup. These are cells that the user changes to setup the sheet. This contains a named range Setup, which includes a variety of values. When the setup is changed, comments that calculate sales forecast recommendations need to be changed. That is the purpose of this code.
When I change the setup, nothing seems to happen with the comments, even though SetupChanged() returns TRUE. When I step through it seems that the WBDays is never = 7 (this is a row of data indicating the number of days in that week, e.g. 5, 7 ,7, 7, 5).
Here is the code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WeeklySalesForecast As Double
Dim WeekIndex As Integer
Dim RecommendedSales As Double
Dim RecommendedSalesString As String
Dim wks As Worksheet
Dim cell As Range
Set wks = wksMonth
' Sales Forecast changed
If SetupChanged(Target) Then
' Fill in the weekly sales forecast recommendation comments
' Clear all the comments
For Each cell In wks.Range("WBSalesForecast")
cell.ClearComments
Next cell
' Fill in comments for full weeks
For WeekIndex = 0 To constWeekCount - 1
If wks.Range("WBDays").Offset(0, WeekIndex).Value = 7 Then
RecommendedSales = 7 / _
wks.Range("WBDays").Offset(0, constTotalDaysColumn).Value _
* wks.Range("SetupSalesForecast").Value
RecommendedSalesString = "Recommended: " & vbCrLf & Format(RecommendedSales, "Currency")
wks.Range("WBSalesForecast").Offset(0, WeekIndex).AddComment RecommendedSalesString
End If
Next WeekIndex
End If
End Sub
When I change one of my setup variables - the total Sales Forecast - I get a type mismatch on the if = 7 statement. I am confused.
Bookmarks