Elikkäs jos haluan matkata ajassa eiliseen käyttämällä excel 2007:skaa.
Tämä koodi lisää uuden sivun taulukkoon ja nimeää sen päivämäärän mukaan.
Sub UusiSivu()
ActiveWorkbook.Unprotect
Dim CurrentDay As Integer
Dim NewName As String
Dim WS As Worksheet
Set WS = ActiveSheet
If IsNumeric(Right(WS.Name, 2)) Then
CurrentDay = Right(WS.Name, 2)
ElseIf IsNumeric(Right(WS.Name, 1)) Then
CurrentDay = Right(WS.Name, 1)
Else
Exit Sub
End If
CurrentDay = CurrentDay 1
NewName = Format(Date, "dd.mm.yyyy")
Dim checkWs As Worksheet
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
'Copies the current sheet to the end of the workbook
Sheets("Default").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = NewName
Range("D2") = NewName
Dim oleObj As OLEObject
Else
Set checkWs = Nothing
MsgBox "Uusi taulukko voidaan lisätä huomenna."
End If
ActiveWorkbook.Protect
End Sub
MUTTA, kuten sanottu minun pitäisi päästä eiliseen päivämäärään käsiksi, ja siihen asti olen päässyt että tällä koodilla se onnistuu
Sub Eilinen()
ActiveWorkbook.Unprotect
Dim CurrentDay As Integer
Dim NewName As String
Dim WS As Worksheet
Set WS = ActiveSheet
If IsNumeric(Right(WS.Name, 2)) Then
CurrentDay = Right(WS.Name, 2)
ElseIf IsNumeric(Right(WS.Name, 1)) Then
CurrentDay = Right(WS.Name, 1)
Else
Exit Sub
End If
CurrentDay = CurrentDay 1
NewName = Format(Date - 1, "dd.mm.yyyy")
Dim checkWs As Worksheet
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
'Copies the current sheet to the end of the workbook
Sheets("Default").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = NewName
Range("D2") = NewName
Dim oleObj As OLEObject
Else
Set checkWs = Nothing
MsgBox "Uusi taulukko voidaan lisätä huomenna."
End If
ActiveWorkbook.Protect
End Sub
MUTTA, kun tuossa koodissa on sellainen juttu että se EI ANNA LISÄTÄ KAHTA PÄIVÄMÄÄRÄÄ SAMANA PÄIVÄNÄ, eli jos siis lisään uuden sivun tänään, sen nimeksi tulee siis 4.10.2011 eikö niin?? Mutta kun haluan lisätä EILISEN päivämäärän, eli 3.10.2011, se ei anna minun lisätä sitä koska koodissa on jokin hätänä. Mitä tuosta pitäisi poistaa että voin lisätä sekä tämänpäivän että eilisen??? Voip olla pikkuisen vaikea selittää mutta kokeilkaa noita koodeja niin selviää tarkemmin.
Tämä koodi lisää uuden sivun taulukkoon ja nimeää sen päivämäärän mukaan.
Sub UusiSivu()
ActiveWorkbook.Unprotect
Dim CurrentDay As Integer
Dim NewName As String
Dim WS As Worksheet
Set WS = ActiveSheet
If IsNumeric(Right(WS.Name, 2)) Then
CurrentDay = Right(WS.Name, 2)
ElseIf IsNumeric(Right(WS.Name, 1)) Then
CurrentDay = Right(WS.Name, 1)
Else
Exit Sub
End If
CurrentDay = CurrentDay 1
NewName = Format(Date, "dd.mm.yyyy")
Dim checkWs As Worksheet
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
'Copies the current sheet to the end of the workbook
Sheets("Default").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = NewName
Range("D2") = NewName
Dim oleObj As OLEObject
Else
Set checkWs = Nothing
MsgBox "Uusi taulukko voidaan lisätä huomenna."
End If
ActiveWorkbook.Protect
End Sub
MUTTA, kuten sanottu minun pitäisi päästä eiliseen päivämäärään käsiksi, ja siihen asti olen päässyt että tällä koodilla se onnistuu
Sub Eilinen()
ActiveWorkbook.Unprotect
Dim CurrentDay As Integer
Dim NewName As String
Dim WS As Worksheet
Set WS = ActiveSheet
If IsNumeric(Right(WS.Name, 2)) Then
CurrentDay = Right(WS.Name, 2)
ElseIf IsNumeric(Right(WS.Name, 1)) Then
CurrentDay = Right(WS.Name, 1)
Else
Exit Sub
End If
CurrentDay = CurrentDay 1
NewName = Format(Date - 1, "dd.mm.yyyy")
Dim checkWs As Worksheet
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
'Copies the current sheet to the end of the workbook
Sheets("Default").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = NewName
Range("D2") = NewName
Dim oleObj As OLEObject
Else
Set checkWs = Nothing
MsgBox "Uusi taulukko voidaan lisätä huomenna."
End If
ActiveWorkbook.Protect
End Sub
MUTTA, kun tuossa koodissa on sellainen juttu että se EI ANNA LISÄTÄ KAHTA PÄIVÄMÄÄRÄÄ SAMANA PÄIVÄNÄ, eli jos siis lisään uuden sivun tänään, sen nimeksi tulee siis 4.10.2011 eikö niin?? Mutta kun haluan lisätä EILISEN päivämäärän, eli 3.10.2011, se ei anna minun lisätä sitä koska koodissa on jokin hätänä. Mitä tuosta pitäisi poistaa että voin lisätä sekä tämänpäivän että eilisen??? Voip olla pikkuisen vaikea selittää mutta kokeilkaa noita koodeja niin selviää tarkemmin.
Vastaukset 1
Vanhimmat
Unohtakaa, mulla ei vaan excel näköjään toimi... :P Mutta kaikki hyvin, olen tällä hetkellä eilisessä päivässä. Huomenna kirjoitan tämän tekstin uudestaan ja pelastan maailman.