macros代码获取合并单元格值与其他单元格值
我在这里附带了示例数据的input文件格式。 有人可以帮助macros代码获得输出数据,如下所述。
macros的input文件:
Roll No Name Mark1 Mark2 1 Abc 10 35 20 25 30 40 2 def 20 10 15 5 25 2 30 3
合并的单元格数据需要在单独的行中与标记数据一起获取。
输出要获取的数据:
Roll No Name Mark1 Mark2 1 Abc 10 35 1 Abc 20 25 1 Abc 30 40 2 def 20 10 2 def 15 5 2 def 25 2 2 def 30 3
看一下这个,
Sub unMerge() Dim i As Long, strA As String, strB As String Range("A:B").unMerge strA = Cells(2, 1) strB = Cells(2, 2) For i = 2 To Cells(Rows.Count, 4).End(xlUp).Row If Cells(i, 1) = "" Then Cells(i, 1) = strA Cells(i, 2) = strB Else strA = Cells(i, 1) strB = Cells(i, 2) End If Next i End Sub
更容易填补空白与公式:
Dim r As Range Set r = Range("A1").CurrentRegion r.UnMerge r.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"