这是我在过去5年中从该站点获得所有帮助后第一次陷入困境。这是我的第一个问题,所以可能不是重点,但是,我会尽力而为。我的源数据类似于图像Snip1,其中A,B和C列被合并并包含一些值,从D列到K,它具有相应的月份值。
输出将如在Snip2中给出的那样,其中A,B和C列的值保持不变,然后在D中是具有某个值的相应月份,然后E列具有该值。如果另一个月份中有一个值,则在第2行中,它将在A,B和C列中放置相同的值,并在相应的月份中放置一个值,然后在E列中放置该值。
这将一直持续到A,B和C列的最后一个填充的单元格。使用Macro可以吗?
Sub Example()
将myRow尽可能长 昏暗的rowPointer只要长 昏暗的ColumnPointer只要长 昏暗的lastColumn只要长 昏暗的LastRowIndex只要
myRow = 1
LastRowIndex = Worksheets(“ sheet1”)。Cells(Rows.Count,1).End(xlUp).Row
For rowPointer = 2 To LastRowIndex
lastColumn = Sheet1.Cells(rowPointer, Columns.Count).End(xlToLeft).Column
For columnPointer = 2 To lastColumn
Sheet2.Cells(myRow, 1).Value = Sheet1.Cells(rowPointer, 1).Value
Sheet2.Cells(myRow, 3).Value = Sheet1.Cells(rowPointer, columnPointer).Value
myRow = myRow + 1
Next columnPointer
Next rowPointer
结束子