I type a value into F6. I don't use formula's in the project I'm making
because I'm using a Dutch version, and the computer, where this workbook is
going to be used on, has an English version of Excel.
In the past, I've noticed that sometimes the formula's didn't work when I
copied the workbook between the two computers.
I've noticed something else... when I use only the messagebox after the
intersect methode, it works, but when I remove the messagebox, and I put some
code after it, that what needs to be done, does not happen.
I'll give an example here:
In range H2 comes a date, which is generated in vbe. In range F6, the user
can type a value. This value needs to be copied to another sheet, depending
on the year of the date in H2.
Code behind:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Set LastCellChanged = Target
dDateChanged = cdate(range("h2").value
iMonthChanged = month(dDateChanged)
iDayChanged = day(dDateChanged)
If Not Intersect(LastCellChanged, Range("f6:f25")) Is Nothing Then
If year(dDateChanged) >= year(now()) then
For year(dDateChanged) = year(now()) to year(now()) + 1
Select case iMonthChanged
Case 1
(Here comes the code for putting the value,
that can be typed in range F6 to F25, on the specific worksheet, in the
specified range)
Case 2
(Here comes the code for putting the value,
that can be typed in range F6 to F25, on the specific worksheet, in the
specified range)
... (until case 12)
end select
next
end if
Else
If Not Intersect(LastCellChanged, Range("h28:al30")) Is Nothing Then
MsgBox "B"
Else
MsgBox "C"
End If
End If
End Sub
I have different ranges that needs to be controled, and ranges that changes
by selecting a value in a combobox. Those ranges don't need to be controled
when they changes, because that's done in the code behind those comboboxes.