#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default date format

Assuming xl2000 or later:

Dim s1 as String, s2 as String
s1 = Date1t.text
s2 = Date2t.text
s1 = Replace(s1,".","/")
s2 = Replace(s2,".","/")


if isdate(s1) then
Date1 = cdate(s1)
else
msgbox "Bad date"
Date1t.Text = ""
exit sub
end if
if isdate(s2) then
Date2 = cdate(s2)
else
msgbox "Bad Date"
Date2t.Text
exit sub
End if


--
Regards,
Tom Ogilvy



Tom,

For some reason I cannot get this to work, dont know why? ive run
through it with F8 and it goes through the code but doesnt replace
anything.

Any ideas what might be wrong?

Duncan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default date format

Duncan,
... butting in ...I tried the code and it works fine
for me (as I expected!)

Are you saying a date like 20.04.06 isn't converted to 20/04/06? i.e. the
Replace is not working?

" wrote:

Assuming xl2000 or later:

Dim s1 as String, s2 as String
s1 = Date1t.text
s2 = Date2t.text
s1 = Replace(s1,".","/")
s2 = Replace(s2,".","/")


if isdate(s1) then
Date1 = cdate(s1)
else
msgbox "Bad date"
Date1t.Text = ""
exit sub
end if
if isdate(s2) then
Date2 = cdate(s2)
else
msgbox "Bad Date"
Date2t.Text
exit sub
End if


--
Regards,
Tom Ogilvy



Tom,

For some reason I cannot get this to work, dont know why? ive run
through it with F8 and it goes through the code but doesnt replace
anything.

Any ideas what might be wrong?

Duncan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default date format

aye!

maybe its me....ill try it again..

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default date format

(I didnt think for one second that Toms code would be wrong, I know
there is something wrong with how im applying it but cant figure it
out........)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default date format

Ok ok, spank me now.

Im gonna paste my code for the benefit of other but it was me being
absolutely stupid.
All I needed to do was show in the textboxes that it had actually
changed

date1t.text = s1
date2t.text = s2

I only found that out when I skipped further and found that it did the
filter ok, then saw that it just wasnt showing me what it was putting
into the filter. (Thank you Toppers...again!)

Many apologies Tom. (full code is below)

(I wonder if it matters that i have used the name s2 already for
something further below?...more testing required)



Private Sub CommandButton1_Click()

Sheets("sheet1").Select

' the below is to replace dots with dashes, but doesnt work yet
Dim s1 As String, s2 As String
s1 = Date1t.Text
s2 = Date2t.Text
s1 = Replace(s1, ".", "/")
s2 = Replace(s2, ".", "/")
If IsDate(s1) Then
Date1 = CDate(s1)
Else
MsgBox "Bad date"
Date1t.Text = ""
Exit Sub
End If
If IsDate(s2) Then
Date2 = CDate(s2)
Else
MsgBox "Bad Date"
Date2t.Text = ""
Exit Sub
End If

Date1t.Text = s1
Date2t.Text = s2

If Date1t.Value <= "" Then
Exit Sub
End If
If Date2t.Value <= "" Then
Exit Sub
End If

Range("D1").End(xlDown).Offset(1, 0).Select
ActiveCell.Select

Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="=" & CLng(Date1),
Operator:=xlAnd _
, Criteria2:="<=" & CLng(Date2)

LOPRdaterange.Hide

Select Case MsgBox("Print?", vbYesNo)
Case vbYes

Sheet1.Activate
Set rng = Range("A1:I" & Range("a65536").End(xlUp).Row)
rng.Select
Selection.PrintOut Copies:=1, Collate:=True


With Worksheets("Sheet1")
Set rng = Intersect(.AutoFilter.Range, .Columns(7))
s = Application.Subtotal(9, rng)
LOPRtot.Value = s
End With


With Worksheets("Sheet1")
Set rng = Intersect(.AutoFilter.Range, .Columns(8))
s2 = Application.Subtotal(9, rng)
LOPRus.Value = s2
End With

Selection.AutoFilter
LOPRdaterange.Show
Exit Sub

Case vbNo

With Worksheets("Sheet1")
Lastrow = .Cells(Rows.Count, "G").End(xlUp).Row
s = 0
For i = 2 To Lastrow
If .Rows(i).Hidden = False Then s = s + .Cells(i, "G")
Next i
End With
LOPRtot.Value = s

With Worksheets("Sheet1")
Lastrow2 = .Cells(Rows.Count, "H").End(xlUp).Row
s2 = 0
For j = 2 To Lastrow2
If .Rows(j).Hidden = False Then s2 = s2 + .Cells(j, "H")
Next j
End With
LOPRus.Value = s2

Selection.AutoFilter
LOPRdaterange.Show

Exit Sub
End Select


Sheets("sheet1").Select

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default date format

If you want, post your w/book with note on sample inputs and I'll look at it.

)

"Duncan" wrote:

(I didnt think for one second that Toms code would be wrong, I know
there is something wrong with how im applying it but cant figure it
out........)


Reply
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
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
How do I convert dd/mm/yy date format to yyddd Julian date format itzy bitzy[_2_] Excel Worksheet Functions 8 December 11th 09 03:20 AM
Convert european foreign date format to US date format EAL Excel Worksheet Functions 1 May 14th 09 10:02 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 11:33 PM.

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"