0

ユーザーフォームからExcelワークシートにデータを挿入するコマンドボタンのこのコードを書きます。問題は私のループにあります。ループでやりたいことは、 の値が の値cells(i,2)と等しい場合ですstrProduct(comboBox)。セル(i,2) に新しい行を挿入し、新しく作成された行に新しいデータを挿入します。cells(i,2) の値が strProduct の値と等しくない場合は、i の次の値に進みます。ここにコードがあります

Private Sub CmdEnter_Click()


    Dim strProduct As String
    Dim intCountData As Long

    strProduct = ComboBox1.Value
    intCountData = Worksheets("Input").Range("B31").Rows.Count


    For i = 32 To intCountData + 31

        If Worksheets("Input").Cells(i, 2) <> strProduct Then
            GoTo finish1:
        Else
            Rows(i).Select
            Selection.Insert Shift:=xlDown
            ActiveCell.Insert.Cells(i, 2) = ComboBox1
            Exit Sub
        End If
    finish1:
    Next

End Sub

i=32 から開始する理由は、行が 32 行から始まるためです。

4

1 に答える 1

0
Private Sub CommandButton1_Click()

    Dim strProduct As String
    Dim intCountData As Long
    strProduct = ComboBox1.Value
    lastrow = Range("a1000").End(xlUp).Row


    For i = 31 To lastrow

        If Worksheets(1).Cells(i, 2) = strProduct Then
            Rows(i).Select
            Cells(i, 2) = ComboBox1.Value
            GoTo finish1
            Exit Sub
        Else
            GoTo finish1
        End If
finish1:
    Next

End Sub
于 2013-02-22T10:27:50.233 に答える