简体   繁体   English

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

[英]Why do I get a Type Mismatch Error

I am attempting to write a subroutine in VBA for Excel to create a customer price list. 我试图在VBA中为Excel编写一个子例程来创建客户价格表。

When I step through the routine I get a type mismatch at the line where I have placed the asterisk. 当我逐步执行例程时,在放置星号的那一行出现类型不匹配的情况。 Can someone explain what I am doing wrong please? 有人可以解释我做错了吗? Below is the code as I written it so far and there may be more errors that I have yet to discover. 下面是我到目前为止编写的代码,可能还有更多错误尚未发现。

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

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

should be: 应该:

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

You need to get the row, which will be a number 您需要获取该行,该行将是一个数字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM