camioneur
camioneur

Reputation: 23

Calendar VBA code for selective cells only

I use the following code with a calendar on a financial spreadsheet in column A only to avoid accidental data entry in columns other than A. I have changed the sheet now to include dates in column "O" so I would like it to include column "A and O" in the code. Would this be possible please?

Private Sub Calendar1_Click()
Columnchk = Mid(ActiveCell.Address, 2, 1)
' set value only if active column = A
If Columnchk = "A" Then ActiveCell.Value = Me.Calendar1.Value
End Sub

Upvotes: 1

Views: 80

Answers (1)

aokozlov
aokozlov

Reputation: 731

If i got the question right, the solution is Or operator:

Private Sub Calendar1_Click()
Columnchk = Mid(ActiveCell.Address, 2, 1)
' set value only if active column = A or O
If Columnchk = "A" Or Columnchk = "O" Then ActiveCell.Value = Me.Calendar1.Value
End Sub

Upvotes: 1

Related Questions