如何从多个范围生成日期列表,并将其与相邻单元格值进行匹配

时间:2017-07-29 03:28:53

标签: excel vba excel-vba

enter image description here

B到D列就是我在原始表格中的内容,接下来的两列是我想通过点击按钮实现的。真的很感激一些VBA编码帮助这个cos我不知道从哪里开始(VBA新手在这里)。

谢谢!

1 个答案:

答案 0 :(得分:0)

我认为此代码可以帮助您解决问题

Dim dStart As Date
Dim dEnd As Date
Dim dDate As Date
Dim iCol As Integer
Dim iColDate As Integer

iCol = 2
iColDate = 2

Do While Cells(iCol, 2).Value <> ""
    dStart = Format(Cells(iCol, 2).Value, "dd/mm/yyyy")
    dEnd = Format(Cells(iCol, 3).Value, "dd/mm/yyyy")
    For dDate = dStart To dEnd
        Cells(iColDate, 6).Value = dDate
        Cells(iColDate, 7).Value = Cells(iCol, 4).Value
        iColDate = iColDate + 1
    Next
    iCol = iCol + 1
Loop