LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Variant userform problem

Hi there i am struggling with this and most likely just cant see the woods
for the trees!

I am relatively new to VBA but getting on reasonably well. My problem hers
is that I have a user form that will, on selection of the relevant cell on
the worksheet (enddate) be shown. Its function is to validate the date
entered by the user and to enter this onto the worksheet or to leave the cell
blank. the following code is fired on enter being clicked.

Public Sub enter_Click()


Dim datecheck As Boolean
Dim yearend
Dim dated As Date
Dim response As Integer
Dim startdate As Boolean
Dim dates


startcheck = False
startdate = IsEmpty(Worksheets("panel form").range("startdate").Value)
If startdate = True Then
MsgBox Title:="No Start Date", prompt:="Please enter the Start Date
before entering an End Date", Buttons:=vbCritical
Me.Hide
Exit Sub
End If
answer = dateend.Value
datecheck = IsDate(answer)
If datecheck = False Then
If Not answer = "" Then
MsgBox Title:="date Error", prompt:=" You have not entered a
correct date, Please use dd/mm/yyyy or dd-mm-yyyy format", Buttons:
=vbCritical
dateend.Value = ""
dateend.SetFocus
Exit Sub
End If
End If

yearend = Worksheets("panelinformation").range("yearend").Va lue
If Not answer = "" Then
dates = answer
dated = DateValue(dates)
End If
If dated = yearend Then

response = MsgBox(Title:="Year End", prompt:="Your End date is beyond the
current Year End date. Do you wish to use this date?", Buttons:=vbYesNo +
vbCritical)
If response = 7 Then
dateend.Value = ""
Frame1.SetFocus
Exit Sub
End If

End If
If Not answer = "" Then
With Worksheets("panel Form")
.Unprotect
.range("enddate").Value = dated

.Protect
End With
Else
With Worksheets("panel Form")
.Unprotect
.range("enddate").Value = answer

.Protect
End With
End If
days
Me.Hide

End Sub


the above is included for info and works ok (improve if you see fit)

The following sub is what i am having problems with I want to calculate days
and weeks here but if the weeks exceed 52 then enddate will have to equal
yearend (which happens to be 31-3-06 at this time)

if enddate is left blank then I assume Yearend.

Public Sub days()

'calculate weeks and days
Dim enddate As Date
Dim yearend As Date
Dim startdate As Date
Dim weeks As Integer
Dim days As Integer
Dim check

check = Worksheets("panel form").range("enddate").Value ' before this line in
locals window "check" is empty and is type variant/empty
'now check has no value and is type is variant/variant(1 to 1, 1 to 5)


MsgBox check ' run time 13 type missmatch here?

yearend = Worksheets("panelinformation").range("yearend").Va lue
enddate = Worksheets("panel form").range("enddate").Value

startdate = (Worksheets("Panel form").range("startdate").Value)
days = (enddate - startdate)
weeks = Int((days / 7))

With Worksheets("panel form")

.Unprotect
.range("weeks").Value = weeks
.range("days").Value = days
.Protect

End With

I would appreciate any comments or help with this cos I have become blind to
the problem which is probably clear!

Thanks

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200603/1
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variant valiables problem [email protected] Excel Discussion (Misc queries) 0 October 8th 08 10:05 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Userform from a Userform Problem Adrian Excel Programming 1 October 12th 05 04:57 PM
VBA problem pulling data out of variant/range input variables [email protected] Excel Programming 2 April 6th 05 04:56 PM


All times are GMT +1. The time now is 11:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"