将所选项发送到单元格

时间:2017-08-02 19:39:56

标签: excel vba excel-vba

我正在尝试获取我拥有的项目并将所有单独的项目启动到其各自的单元格中。

With Me.selecteditems
    For i = 1 To .ListCount - 1
        If .Selected(i) Then
            found = True
            On Error Resume Next
            str = ThisWorkbook.Sheets(9).Range("A1:Cells(i, 1)")
            quantity = ThisWorkbook.Sheets(9).Range("A1:Cells(i, 2)")
            On Error GoTo 0
        End If
    Next i
End With

以下代码的这一部分应该放置来自代码较长部分的项目,并放入项目str和金额quantity。我尝试了不同的方法,就在最近我尝试重复它之前的情况,它并没有那么好。也没有错误,它抛出了我:

  

应用程序定义或对象定义的错误

整个代码:

Dim i As Long, j As Long, ii As Long
Dim found As Boolean
Dim str As String
Dim message, title, defaultval As String
Dim quantity As String


With Me.selecteditems
    For i = 0 To .ListCount - 1
        If .Selected(i) Then
            found = True
            For ii = 0 To .ColumnCount - 1
                If str = "" Then
                    str = .List(i, ii) & vbTab
                Else
                    If ii < .ColumnCount - 1 Then
                        str = str & .List(i, ii) & vbTab
                    Else
                        str = str & .List(i, ii)
                    End If
                End If
            Next ii
            message = "How much" & vbCrLf & str & "?"
            title = "Amount"
            defaultval = "1"
            quantity = InputBox(message, title, defaultval)
            str = str & "  x  " & quantity & vbNewLine
        End If
    Next i
End With

With Me.selecteditems
    For i = 1 To .ListCount - 1
        If .Selected(i) Then
            found = True
            On Error Resume Next
            str = ThisWorkbook.Sheets(9).Range("A1:Cells(i, 1)")
            quantity = ThisWorkbook.Sheets(9).Range("A1:Cells(i, 2)")
            On Error GoTo 0
        End If
    Next i
End With

0 个答案:

没有答案