Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA基于其他表中的输入派生或转换新表_Vba_Excel - Fatal编程技术网

Excel VBA基于其他表中的输入派生或转换新表

Excel VBA基于其他表中的输入派生或转换新表,vba,excel,Vba,Excel,尝试确定将用户输入表转换为机器可读表的VBA解决方案。我查看了许多VBA和Excel表格线程,但找不到符合要求的内容 简单地说,我们在仅持续数月的领域管理了大量促销活动。用户希望提供下表: PROMOTION | REGION | STATE | FirstMonth | LastMonth VERGO | MIDWEST | ILLINOIS | 1/31/14 | 3/31/15 在我们对地区/州/月份执行查找以确定给定月份的费用后,希望将此表与他们一起接收回来。经过审

尝试确定将用户输入表转换为机器可读表的VBA解决方案。我查看了许多VBA和Excel表格线程,但找不到符合要求的内容

简单地说,我们在仅持续数月的领域管理了大量促销活动。用户希望提供下表:

PROMOTION | REGION | STATE | FirstMonth | LastMonth VERGO | MIDWEST | ILLINOIS | 1/31/14 | 3/31/15 在我们对地区/州/月份执行查找以确定给定月份的费用后,希望将此表与他们一起接收回来。经过审查后,它将提供给我们的财务合作伙伴,以帮助预算

DATE | PROMOTION | REGION | STATE | FEE 1/31/14 | VERGO | MIDWEST | ILLINOIS | 100 2/28/14 | VERGO | MIDWEST | ILLINOIS | 100 3/31/14 | VERGO | MIDWEST | ILLINOIS | 100 4/30/14 | VERGO | MIDWEST | ILLINOIS | 120 5/31/14 | VERGO | MIDWEST | ILLINOIS | 120 ...ECT 5/31/15 | VERGO | MIDWEST | ILLINOIS | 175 我正在努力寻找一些可以使用的逻辑,首先从初始表中读取一行,然后根据促销的第一个月和最后一个月之间的间隔时间,复制/粘贴该行X次


有没有关于如何处理的指针?

我会循环工作表1中的数据行,并在其中从第一个月循环到最后一个月,然后将数据写入工作表2:

Sub createMonthlyTable()
 Set oWs1 = ActiveWorkbook.Worksheets(1)
 Set oWs2 = ActiveWorkbook.Worksheets(2)

 lStartrowWs1 = 2
 lLastrowWs1 = oWs1.Cells(2, 1).End(xlDown).Row

 lRowWs2 = 2

 For i = lStartrowWs1 To lLastrowWs1
  With oWs1
   sPromotion = .Cells(i, 1).Value
   sRegion = .Cells(i, 2).Value
   sState = .Cells(i, 3).Value
   dFirstMonth = .Cells(i, 4).Value
   dLastMonth = .Cells(i, 5).Value
   dMonth = dFirstMonth
   Do While dMonth <= dLastMonth
    With oWs2
     .Cells(lRowWs2, 1).Value = dMonth
     .Cells(lRowWs2, 2).Value = sPromotion
     .Cells(lRowWs2, 3).Value = sRegion
     .Cells(lRowWs2, 4).Value = sState
     dMonth = DateSerial(Year(dMonth), Month(dMonth) + 2, 1) - 1
     lRowWs2 = lRowWs2 + 1
    End With
   Loop
  End With
 Next
End Sub
问候

阿克塞尔