简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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