为什么会出现类型不匹配错误

时间:2016-09-28 12:45:51

标签: excel vba

我正在尝试在VBA for Excel中编写子程序来创建客户价格表。

当我单步执行例程时,我在放置星号的行处出现类型不匹配。有人可以解释我做错了吗?下面是我到目前为止编写的代码,可能还有更多错误,我还没有发现。

Sub Create_Customer_Price_List()

    Dim Counter1 As Integer
    Dim Counter2 As Integer
    Dim SectionNum As Integer
    Dim ProdNum As Integer
    Dim ProductID As String
    Dim ProductSection As String

    Worksheets("BH").Activate

    SectionNum = Range("J10", Range("J10").End(xlDown)).Rows.Count
    Range("J10").Select

    For Counter1 = 1 To SectionNum
        If ActiveCell.Value <> 0 Then
        ProductSection = ActiveCell.Offset(0, 1).Value
 *       Range("B9").Offset(Range("B9").End(xlDown), 3).Value = ProductSection


        End If

            ProdNum = Range("J10").Value

            For Counter2 = 1 To ProdNum
            ProductID = Range("L10").Value & Counter2

            Range("B9").Offset(Counter2, 0).Value = ProductID

            Next Counter2
        Range("J10").Offset(Counter1 + 1, 0).Select

    Next Counter1

End Sub

1 个答案:

答案 0 :(得分:1)

Range("B9").Offset(Range("B9").End(xlDown), 3).Value = ProductSection

应该是:

Range("B9").Offset(Range("B9").End(xlDown).Row, 3).Value = ProductSection

您需要获取行,这将是一个数字