Har du set hvor smart det kan være?

Microsoft Office, Word skabeloner, Excel regnearkSmart Office Word skabelon system

SmartOffice - EnterShortDates

Hurtig indtastning af datoer i et givent område i et ark



Eksempel 1

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sDateString As String, sCurYear As String, sCurMonth As String
    If Not Intersect(Target, Range("A1:A100")) Is Nothing Then
        sCurYear = Year(Now()): sCurMonth = Month(Now())
        If Not IsNumeric(Target.Value) Then
            If Not IsDate(Target.Value) Then GoTo errDate
            If Target.Value >= CDate("01-01-" & sCurYear) And Target.Value <= CDate("31-12-" & sCurYear) Then Exit Sub
            sDateString = CLng(Target.Value)
        Else
            sDateString = Target.Value
        End If
        
        Application.EnableEvents = False
        Select Case Len(sDateString)
            Case 1: sDateString = "0" & sDateString & "-" & sCurMonth & "-" & sCurYear
            Case 2: sDateString = sDateString & "-" & sCurMonth & "-" & sCurYear
            Case 3: sDateString = "0" & Left(sDateString, 1) & "-" & Right(sDateString, 2) & "-" & sCurYear
            Case 4: sDateString = Left(sDateString, 2) & "-" & Right(sDateString, 2) & "-" & sCurYear
            Case 5: sDateString = "0" & Left(sDateString, 1) & "-" & Mid(sDateString, 2, 2) & "-" & Left(sCurYear, 2) & Right(sDateString, 2)
            Case 6: sDateString = Left(sDateString, 2) & "-" & Mid(sDateString, 3, 2) & "-" & Left(sCurYear, 2) & Right(sDateString, 2)
            Case 8: sDateString = Left(sDateString, 2) & "-" & Mid(sDateString, 3, 2) & "-" & Right(sDateString, 4)
        End Select
        If IsDate(sDateString) Then
            If sDateString >= CDate("01-01-" & sCurYear) And sDateString <= CDate("31-12-" & sCurYear) Then
                Target.Value = CDate(sDateString)
            Else
                GoTo errDate
            End If
        Else
            GoTo errDate
        End If
        Application.EnableEvents = True
    End If
    
    Exit Sub
errDate:
    MsgBox "Ulovlig dato!" & vbCrLf & vbCrLf & "Indtast en ny dato", vbCritical + vbOKOnly, "Systeminformation"
    Target.Value = "": Target.Select
    Application.EnableEvents = True
End Sub


Test disse forskellige dato'er f.eks.: 5 for 05-03-2011 (hvis i dag er marts måned i 2011), 14 for 14-03-2011 (hvis i dag er marts måned i 2011), 504 for 05-04-2011 (hvis i dag i år 2011), 1406 for 14-06-2011 (hvis i dag i år 2011), 71011 for 07-10-2011, 210811 for 21-08-2011

   

Smart Office Freeware Smart Data Management
Compare 2 Columns
Excel Super- Subscript
Teachers Excel Tools
         
Smart Office - Word og Excel specialist