That is certainly not my intention. I am self-teaching myself (as I do a lot of things). I apologize, but I learn best by working through examples. I have edited your code to the following:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ErrMsg As String
Dim C As Range
For Each C In Target
If C.Column = 1 And C.Row > 1 And C <> "" Then
If Sheets("Sheet2").Range("F1") = "" Then
ErrMsg = "You must enter a month where shown"
End If
If Sheets("Sheet2").Range("F2") = "" Then
ErrMsg = ErrMsg & vbCrLf & "You must enter a year where shown"
End If
If ErrMsg <> "" Then
MsgBox ErrMsg
Else
If C > Day(DateSerial(Sheets("Sheet2").Range("F2"), Sheets("Sheet2").Range("G1") + 1, 1) - 1) Or C <= 0 Then
MsgBox "You have entered a day of the month that is not valid for the month you entered."
C.NumberFormat = "General"
Else
Application.EnableEvents = False
C = DateSerial(Sheets("Sheet2").Range("F2"), Sheets("Sheet2").Range("G1"), C)
Application.EnableEvents = True
End If
End If
End If
Next C
End Sub
My specific VBA code question is: How would I extend this code to multiple columns?
I tried
If C.Column = 1,3,5 And C.Row > 1 And C <> "" Then
but that did not work. I've never seen a range defined the way you did it, so I am just lost. I would appreciate any help you might be able to give me.
Bookmarks