code for date between two dates vba
Hello,
I need help to make my code work..It' s a little bit frustrating.
I want the Userform to atomatically fill the other fields when The date (d)
and Time(t) are filled. I need vba to make automatically calculations in two periodes:
- from 1st june til nov
- from nov til june
Thanks in advance for you help.
Yhe code lokks like this:
Private Sub CommandButton1_Click()
Dim d As Date, t As Date, startTime1 As Date, startTime2 As Date, startTime3 As Date, Op As String, Vgem As String
d = CDate(TextBox1.Text)
d = TextBox1.Value
TextBox1.Value = Format(TextBox1.Value, "DD-MM-YYYY")
t = CDate(TextBox2.Text)
t = TextBox2.Value
TextBox2.Value = Format(TextBox2.Value, "hh:mm")
startTime1 = #1/6/2014#
startTime2 = #1/11/2014#
startTime3 = CDate("06:00")
startTime3 = CDate("20:00")
Range("b2").Value = d
Range("a2").Value = "Date"
Range("c1").Value = "Opbrengst"
Range("d1").Value = "Gemiddel dagverbruik"
If d > startTime1 And startTime2 > d Then Op = (2690 * (1 / 180))
TextBox3.Value = Op
TextBox3.Value = Format(TextBox3.Value, "0.000")
Range("c2").Value = TextBox3.Value
If d > startTime1 And startTime2 > d Then Vgem = 4120 * (1 / 180)
TextBox4.Value = Vgem
TextBox4.Value = Format(TextBox4.Value, "0.000")
Range("d2").Value = TextBox4.Value
End Sub
you'd need to add a sample
you'd need to add a sample file for someone to be able to help you... login, edit your post and add the attachment