Referring Date in VBA

A

anupam

If c.Value <= #7/8/2004# Then
c.Value = #7/1/2004#
End If

but in this code i want to refer month as variable. i will accept th
month from user using inputbox.

how can i use variable for month in this code.

??????
 
T

Tom Ogilvy

Dim res as String, lMon as Long
Dim dt as Date, dt1 as Date
res = InputBox("Enter Month as a number from 1 to 12)
if res = "" then exit sub
if isnumeric(res) then
lMon = clng(res)
if lMon >= 1 and lMon <= 12 then
set dt = DateSerial(2004,lMon,8)
set dt1= DateSerial(2004,lMon,1)
if c.Value <= dt then
c.Value = dt1
End if
end if
Else
msgbox "Invalid entry"
End if
 
Top