我想合併那章重複章只到一個單元格。Excel VBA:合併循環內的範圍
這是我的代碼如何循環。
Dim label As Control
Dim itm As Object
For ctr = 1 To InfoForm.Chapter.ListCount - 1
For Each label In InfoForm.Controls
If TypeName(label) = "Label" Then
With ActiveSheet
i = i + 1
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + IIf(i = 1, 1, 0)
lastColumn = .Cells(i, .Columns.Count).End(xlToLeft).Column
If label <> "Chapter" Then
.Cells(lastColumn, i).Value = "Chapter " & ctr
.Cells(lastRow, i).Value = label.Caption
End If
End With
End If
Next
Next
我試圖合併它像這樣
.Range(Cells(1, lastColumn), Cells(1,i)).Merge
不過它把所有重複的章節爲一個單元,而不是
你能提供預期輸出的例子嗎? – MiguelH
這是我的預期結果 –
我發現有關表單控件的代碼有點混亂......你只是試圖合併一堆保持相同值的單元格,不是嗎? –