Referring Date in VBA

  • Thread starter Thread starter anupam
  • Start date Start date
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.

??????
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top