1

私はこれに対する答えを長い間探してきました:

以下のコードを使用して、一意の値の各セットの最後に空の行を入力したいと思います。キッカーは、ユーザーが列範囲のキー文字を入力できるプロンプトを表示することです。私はそれらのいくつかを試しましたが、「B」をクエリの回答に置き換えることはできません。

Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 2 Step -1
If Cells(lRow, "B") <> Cells(lRow - 1, "B") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub

助言がありますか?

4

4 に答える 4

1

これを試して

Sub Demo()
    Dim lRow As Long
    Dim sCol As String
    sCol = InputBox("Enter Column", sCol)
    For lRow = Cells(Cells.Rows.Count, sCol).End(xlUp).Row To 2 Step -1
        If Cells(lRow, sCol) <> Cells(lRow - 1, sCol) Then
            Rows(lRow).Insert
        End If
    Next lRow
End Sub
于 2013-02-06T01:15:27.793 に答える
1

あなたの質問は、ユーザーが列として「B」、「AA」、「C」を入力できるようにしたいということだと思いますか?

@Chrisのコードを部分的にコピーする

Sub Demo()
    Dim lRow As Long
    Dim sCol As String
    Dim colNum as string
    sCol = InputBox("Enter Column", sCol)
    colNum  = columns(sCol).column
    For lRow = Cells(Cells.Rows.Count, colNum  ).End(xlUp).Row To 2 Step -1
        If Cells(lRow, colNum  ) <> Cells(lRow - 1, colNum  ) Then
            Rows(lRow).Insert
        End If
    Next lRow
End Sub
于 2013-02-06T06:01:11.107 に答える
0

開いているプロンプトを含めて、これは私が最終的に使用したものです。
開くプロンプトをボタンに接続して、非技術者が使いやすくしました。

Sub InsertRowAtChangeInValue()

    Dim customerBook As Workbook
    Dim filter As String
    Dim caption As String
    Dim customerFilename As String
    Dim customerWorkbook As Workbook
    Dim targetWorkbook As Workbook

    Set targetWorkbook = Application.ActiveWorkbook

    filter = "Excel 2007 files (*.xlsx),*.xlsx, Excel 97-03 files (*.xls),*xls, All files (*.*),*.*"
    caption = "Please select an input file."
    customerFilename = Application.GetOpenFilename(filter, , caption)

    Set customerWorkbook = Application.Workbooks.Open(customerFilename)

    Dim targetSheet As Worksheet
    Set targetSheet = targetWorkbook.Worksheets(1)
    Dim sourceSheet As Worksheet
    Set sourceSheet = customerWorkbook.Worksheets(1)

    targetSheet.Range("A1", "AR5000").Value = sourceSheet.Range("A1", "AR5000").Value

    Dim lRow As Long
    Dim sCol As String
    Dim colNum As String
    sCol = InputBox("Enter Column", sCol)
    colNum = Columns(sCol).Column
    For lRow = Cells(Cells.Rows.Count, sCol).End(xlUp).Row To 2 Step -1
        If Cells(lRow, sCol) <> Cells(lRow - 1, sCol) Then
            Rows(lRow).Insert
        End If
    Next lRow
End Sub

助けてくれてありがとう!

于 2013-02-06T18:43:04.530 に答える
0

Range("B" & Cells.Rows.Count)代わりにCells(Cells.Rows.Count, "B")、残りについても同様に試してください。

于 2013-02-05T19:58:55.150 に答える