我提供你的VBA代碼對於這個問題,有意見,以幫助你瞭解這個過程。
請花時間閱讀並理解正在發生的事情,所以下次遇到像這樣的問題時,您就知道從哪裏開始。如果你有困難並且陷入困境,那麼可以隨時尋求幫助,但要提供有關您所使用的代碼/公式的信息。
Sub ExampleMacro()
' Define the variables
Dim LastRow As Long
Dim addrows
Dim FindDates
Dim CountDays
Dim adddays
Dim i As Long
Dim ir As Long
' Workout number of rows containing data to process
With Sheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row - 1
End With
' This is the row number we want to start processing, every time the For runs, it will add another 1 to this number so the next row is processed
addrows = 2
' Loop through until, LastRow has been reached
For ir = 1 To LastRow
' Define the number of days between the two dates
FindDates = Sheets("Sheet1").Range("B" & addrows).Value
' Define the number of days between the two dates
CountDays = Sheets("Sheet1").Range("C" & addrows).Value - Sheets("Sheet1").Range("B" & addrows).Value + 1
' Define the date to enter into Data column on Sheet 2, every time it loops through the date will be increased by 1
adddays = 0
' Loop through until, the last date has been reached
For i = 1 To CountDays
' Insert a new blank row on Sheet2 - Row2, for the data to be entered
Sheets("Sheet2").Rows("2:2").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
' Put ID value of the row into Sheet2
Sheets("Sheet2").Range("A2").Value = Sheets("Sheet1").Range("A" & addrows).Value
' Put the date into Sheet2
Sheets("Sheet2").Range("B2").Value = FindDates + adddays
' Put the Code into Sheet2
Sheets("Sheet2").Range("C2").Value = Sheets("Sheet1").Range("D" & addrows).Value
' Increase the date by 1 day, ready for the re run of this loop
adddays = adddays + 1
' Go back to i and carry on until the number of CountDays has been matached.
Next I
' Now that all the dates for the first row of data has been processed, increase the row number by 1
addrows = addrows + 1
' Go back to ir and carry on until the number of rows with data has been completed
Next ir
End Sub
在您的輸出中,哪裏是6/10,7/10,8/10,... 15/10/2016?您可以拖動日期,並將日期一次增加一天。這不行嗎?你試過什麼了?這是一件非常簡單的事情,你應該在網上找到很多提示。請顯示你的嘗試,什麼/沒有工作。 – BruceWayne
日期是數字,下一個循環將有所幫助。一點研究會爲你找到它。 Google搜索它大約422,000個結果(0.80秒) –
@brucewayne認爲o/p意味着直到當前日期(或某事):)或結束日期更早更早。 –