Sub test()
lr = Sheets(1).Range("A1:A" & Rows.Count).End(xlDown).Row
For i = 2 To lr
If Sheets(1).Cells(i, 2).MergeCells = True Then
Sheets(1).Range(Cells(i, 2).MergeArea.Address).UnMerge
Sheets(1).Range(Cells(i, 3).MergeArea.Address).UnMerge
nr = Sheets(1).Range(Cells(i, 2), Cells(Rows.Count, 2)).End(xlDown).Row
If nr < lr Then
nr1 = nr
Else
nr1 = lr + 1
End If
For j = i To nr1 - 1
Sheets(1).Cells(j, 2).Value = Cells(i, 2).Value
Sheets(1).Cells(j, 3).Value = Cells(i, 3).Value
Next j
End If
i = nr - 1
Next i
End Sub
試試上面的代碼。這可能會幫助你。
Sub test()
Dim arr() As String
dim arr2() as string
For i = 2 To Rows.Count
If Not Cells(i, 1).Value = "" Then
val2 = Sheets(1).Cells(i, 2).Value
val3 = Sheets(1).Cells(i, 3).Value
arr = Split(Sheets(1).Cells(i, 1).Value, Chr(10))
arr2 = Split(Sheets(1).Cells(i, 4).Value, Chr(10))
cnt = UBound(arr)
Sheets(1).Rows(i & ":" & i + cnt - 1).EntireRow.Insert
For j = i To i + cnt
Sheets(1).Cells(j, 1).Value = arr(j - i)
Sheets(1).Cells(j, 4).Value = arr2(j - i)
Sheets(1).Cells(j, 2).Value = val2
Sheets(1).Cells(j, 3).Value = val3
Next j
i = i + cnt
Else: Exit For
End If
Next i
End Sub
確保在A列中的行之間沒有空白。此代碼將爲alt + enter分隔的值起作用。
您必須取消合併單元格,並且這些值將位於未合併範圍的第一個單元格中,然後將其複製直至出現下一個值。您可以遍歷B列以檢查merge = true,然後將其設置爲false,然後您可以將範圍的值複製到單元格的其餘部分 –
您可以提供有關您嘗試執行此操作的步驟的更多特定信息嗎? – Kyle
我試圖拆分單元格,粘貼特殊(轉置),並手動更改此設置,但我不是技術精明,我列出的所有選項都花費太長時間,因爲有大約600行我需要完成此操作。還應該注意細胞沒有合併,而是我輸入alt - 輸入 – Banjo