-1

Excel ドキュメントをクリーンアップするマクロを作成する必要があります。現在、ほとんどの機能が動作していますが、2 行のデータを結合するのに問題があります。最初に 2 行のデータをマージしてから、2 行目を削除する必要があります。このコード ブロックは、私が問題を抱えている関数からのものです。正しい行を削除していますが、最初に削除したい行を上の行とマージして、データが失われないようにしたいと思います。行全体を結合する簡単なコマンドがあるかどうか、またはセルごとに実行する必要があるかどうかは誰にもわかりません。

For RowCount = Selection.Rows.Count To 1 Step -1

    ' Delete rows that don't have text in col A
    If Selection.Cells(RowCount, 1).Text <> "" And IsNumeric(Selection.Cells(RowCount, 1).Value) Then
        'Is Number


    ElseIf Selection.Cells(RowCount, 1).Text = "Heading" Then
        'Its the Heading
    Else

        'Its not needed!
        '*********************************************************
        'CODE TO MERGE TWO ROWS SHOULD GO HERE********************
        '(MERGE ROWCOUNT-1 WITH ROWCOUNT AND DELETE ROWCOUNT)*****
        '*********************************************************

        Selection.Rows(RowCount).EntireRow.Delete
    End If

' Start next iteration of RowCount loop.
Next RowCount
4

1 に答える 1

1

セルごとに行う必要があると思います。

交換:

'*********************************************************
'CODE TO MERGE TWO ROWS SHOULD GO HERE********************
'(MERGE ROWCOUNT-1 WITH ROWCOUNT AND DELETE ROWCOUNT)*****
'*********************************************************

と:

Dim ColumnCount As Integer, intCnt As Integer
ColumnCount = Selection.columns.count

For intCnt = 1 To ColumnCount

    Dim strRow As String, strPrevRow As String
    strRow = Selection.Cells(RowCount, intCnt).Text
    strPrevRow = Selection.Cells(RowCount, intCnt).offset(-1).Text

    Selection.Cells(RowCount, intCnt).offset(-1) = strRow & " " & strPrevRow

Next
于 2012-06-21T18:57:25.680 に答える