I just start to learn VBA, please help me to fix this error

  • Hi, i start ro learn VBA. This is my first project and i get stuck at input data through form to the next empty row. I try to fixed it with watch so many videos about it for 4 days, but i still can't fix it. So please kindly tell me, why i get this error and how to fix it. Thank you.


    These are my vba codes.

    n = Worksheets("ListItem").Range("TglOrderMasuk" & Rows.Count).End(xlUp).Row + 1
    Worksheets("ListItem").Range("TglOrderMasuk" & n).Value = txbOrderMasuk.Value Worksheets("ListItem").Range("NamaBuyer" & n).Value = txbBuyer.Value Worksheets("ListItem").Range("KodePO" & n).Value = txbPO.Value Worksheets("ListItem").Range("NamaProduk" & n).Value = txbNamaBarang.Value Worksheets("ListItem").Range("JenisWig" & n).Value = txbJenisWig.Value Worksheets("ListItem").Range("QtyOrder" & n).Value = txbQOrder.Value

  • I assume that TglOrderMasuk and the others are single cell named ranges of the column headers. If so, to use them you need to extract the range's column to use it in the format you have shown.


    Code
    1. With Worksheets("ListItem")
    2. n = .Cells(Rows.Count, .Range("TglOrderMasuk").Column).End(xlUp).Row + 1
    3. .Cells(n, .Range("TglOrderMasuk").columnn).Value = txbOrderMasuk.Value
    4. '...
    5. '... and so on.
    6. End With

    Better would to just use the column's number...


    Code
    1. With Worksheets("ListItem")
    2. n = .Cells(Rows.Count, 2).End(xlUp).Row + 1
    3. .Cells(n, 2).Value = txbOrderMasuk.Value
    4. '...
    5. '... and so on.
    6. End With

    If I've been helpful, let me know. If I haven't, let me know that too.