Pete634
01-08-2007, 05:19 PM
Hi,
Can anyone help with a problem I am having with a userform? I'm building a master timesheet that will manipulate holidays etc on employees sheets as well as store & maniplate data on the master... won't go into it as I know what I need to do, but I'm clearly missing some basics (basic knowledge probably!!)
I've created the userform (to select the Employee, dates etc) and initialized it. In the form one of my textboxes is called HStartDay (the day the holiday starts) , another is HStartMth (the month the holiday starts). Under Private Sub UserForm_initialise, the only reference to these two cells is as follows:-
Private Sub UserForm_Initialize()
(other code before the following)
HStartDay.Value = ""
HStartMth.Value = ""
(other code after)
End Sub
When the data is entered on to the form and the user presses an "OK" button then I want to check that
HStartMth is not > 12
HStartDay is not > the maximum number of days in the month of HStartMth
The part code I used under Private Sub HformOK_Click() where this is my button on the holday form is : -
If HStartMth > 12 Then
MsgBox "Invalid Date"
HStartMth.Value = ""
HStartMth.SetFocus
Exit Sub
End If
....This works fine
If HStartDay.Value > Worksheets("data").Cells(4 + HStartMth, 4).Value Then
MsgBox "Invalid Date"
HStartDay.Value = ""
HStartDay.SetFocus
Exit Sub
End If
... This doesn't.
So you know, on Sheet "Data" Cells B5-D16 are populated with row B (1-12), row C (Jan-Dec), row D (max number of days in corresponding month).
I've tried everything I can think of (which isn't a lot!!).
If I try and put HStartDay into a cell on Data and then code to compare the relevant cells this doesn't work either. The cell on the worksheet says the number is formatted as text and if I format the cell and then run the macro it changes the format back to general.
Does it matter that I haven't used DIM anywhere yet?
Does anyone have any ideas? Please help a sad VBA newbie !
Apologies for the long post.
Can anyone help with a problem I am having with a userform? I'm building a master timesheet that will manipulate holidays etc on employees sheets as well as store & maniplate data on the master... won't go into it as I know what I need to do, but I'm clearly missing some basics (basic knowledge probably!!)
I've created the userform (to select the Employee, dates etc) and initialized it. In the form one of my textboxes is called HStartDay (the day the holiday starts) , another is HStartMth (the month the holiday starts). Under Private Sub UserForm_initialise, the only reference to these two cells is as follows:-
Private Sub UserForm_Initialize()
(other code before the following)
HStartDay.Value = ""
HStartMth.Value = ""
(other code after)
End Sub
When the data is entered on to the form and the user presses an "OK" button then I want to check that
HStartMth is not > 12
HStartDay is not > the maximum number of days in the month of HStartMth
The part code I used under Private Sub HformOK_Click() where this is my button on the holday form is : -
If HStartMth > 12 Then
MsgBox "Invalid Date"
HStartMth.Value = ""
HStartMth.SetFocus
Exit Sub
End If
....This works fine
If HStartDay.Value > Worksheets("data").Cells(4 + HStartMth, 4).Value Then
MsgBox "Invalid Date"
HStartDay.Value = ""
HStartDay.SetFocus
Exit Sub
End If
... This doesn't.
So you know, on Sheet "Data" Cells B5-D16 are populated with row B (1-12), row C (Jan-Dec), row D (max number of days in corresponding month).
I've tried everything I can think of (which isn't a lot!!).
If I try and put HStartDay into a cell on Data and then code to compare the relevant cells this doesn't work either. The cell on the worksheet says the number is formatted as text and if I format the cell and then run the macro it changes the format back to general.
Does it matter that I haven't used DIM anywhere yet?
Does anyone have any ideas? Please help a sad VBA newbie !
Apologies for the long post.