1
我有這個簡單的電子表格名稱和幾個日期。excel:獲取日期並添加一天
我想要發生的是,如果某些條件是真的,我會得到第一張紙的結束日期(H列)並將其複製到我的第二張紙(G列),並在其上添加更多日期。
這是第一張紙,名爲BASE_TOTAL
。
這是第二個,叫APOIOS
。
的「SSS」表示我想用日期加一天進入。
這是我到目前爲止已經試過:
Sub Apoios()
Dim i As Long
Dim j As Long
Dim lastrow As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim res
Set ws1 = Sheets("Plan3")
Set ws2 = Sheets("BASE_TOTAL")
Set ws3 = Sheets("APOIOS")
lastrow = ws2.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
For j = 1 To 11
Select Case True
Case IsEmpty(ws2.Cells(i, j)):
ws3.Cells(i, j) = ""
Case Not IsEmpty(ws2.Cells(i, j)):
If ws1.Cells(4, 3) <= ws2.Cells(i, 8) And ws2.Cells(i, 5).Value <> "APOIO" Then
ws3.Cells(i, 1).Value = ws2.Cells(i, 1)
ws3.Cells(i, 2).Value = ws2.Cells(i, 2)
ws3.Cells(i, 3).Value = ws2.Cells(i, 3)
ws3.Cells(i, 4).Value = ws2.Cells(i, 4)
ws3.Cells(i, 5).Value = "APOIO"
ws3.Cells(i, 6).Value = "-"
ws3.Cells(i, 7).Value = ws2.Cells(i, 8).Value + 1
ws3.Cells(i, 8).Value = "-------------"
ws3.Cells(i, 9).Value = ws2.Cells(i, 9)
ws3.Cells(i, 10).Value = ws2.Cells(i, 10)
ws3.Cells(i, 11).Value = ws2.Cells(i, 11)
End If
End Select
Next j
Next i
End Sub
正如你所看到的,我想這樣做這一行代碼:
ws3.Cells(i, 7).Value = ws3.Cells(i, 8).Value + 1
但它沒有工作出。我對VBA很有新意,所以我不知道應該使用哪個函數來理解,我希望在該單元格上添加日期,並且再添加一天。
我知道存在DateSerial
函數,但我不知道如何將其應用於此示例。我也發現THIS的答案,我會檢查它是否有效。 雖然我的日期格式爲dd/mm/yyyy
。
任何建議都會有幫助。
我得到這行突出顯示一個類型不匹配的錯誤。 – paulinhax
我只是測試它,它爲我工作。 是格式化爲日期的列嗎?或者是否有一些數據不是列中的日期? – RealCheeseLord
整列按日期格式化,但我的日期格式爲'dd/mm/yyyy'格式。這個函數得到或我需要修改一些東西? – paulinhax