Modify code to transfer data to template

  • Hello,


    I have a code that I have been using for some time now. I have to make some changes which requires adding another column to the template but I am having trouble getting the data to transfer to the correct cells.


    The code I have is as following:




    I have populated the list box with a dynamic name range list which is 4 columns wide but only 3 of those are needed on this particular template. One column is for information purpose only and is not needed on the template.


    If I use this code on a test sheet without merged cells it works just like I need it to. But my template has merged cells where the second column of the name range is going. It places the first item from the list in the second column on the template, second item in the third (Merged) column and fails to place the last item on the list in the fourth column.


    I have attached a screenshot of the template, Hope that helps.


    Thank you in advance for your help.

  • Re: Modify code to transfer data to template


    What columns specifically are you trying to write to?


    It looks like you are writing to column 2 twice


    Code
    addme.Offset(0, 2) = Me.lstConstructionRetail.List(X, 2) 
                addme.Offset(0, 2) = Me.lstConstructionRetail.List(X, 3)
  • Re: Modify code to transfer data to template


    Oh ooppss that second 2 should not be there. I have been playing with the code for a couple days now and must have changed that at some point.


    I did go back into my template and corrected that and it still does not put the last item in the list box in column I.


    I'm trying to write to columns B, C (C:H Merged) and I. The I column is where I'm having trouble.


    (Column A is where the quantity is typed in)
    Column B = Rev Code (First item in the list box)
    Column C (C:H Merged) = Item Description (Second item in the list box)
    Column I = Item Price (Fourth item in the list box)


    The third item in the list box is the supplier and is there for sales staff info only and does not need to appear on the Invoice.


    Hope that makes it a bit clearer.


    Thank you!

  • Re: Modify code to transfer data to template


    I think I understand. I think all you need to do is change


    Code
    addme.Offset(0, 1) = Me.lstConstructionRetail.List(X, 1) 
           addme.Offset(0, 2) = Me.lstConstructionRetail.List(X, 2) 
           addme.Offset(0, 2) = Me.lstConstructionRetail.List(X, 3)


    to this

    Code
    addme.Offset(0, 1) = Me.lstConstructionRetail.List(x, 1)
        addme.Offset(0, 2) = Me.lstConstructionRetail.List(x, 2)
        addme.Offset(0, 8) = Me.lstConstructionRetail.List(x, 4)   ' <------offset(rows, columns), I = 8 assuming we offset from A: 4 I believe should be the 4th item in your list
  • Re: Modify code to transfer data to template


    That is giving me a runtime error "Could not get list property. Invalid argument". I changed my list to 5 columns to see if that would work and the error doesn't come up but still doesn't put the price in column I.

  • Re: Modify code to transfer data to template


    It's a pretty large workbook. Can I email it to you?


    My list has the Rev Code, Item Description, Supplier and Price.

  • Re: Modify code to transfer data to template


    The max upload limit is 205.1 KB. Does your file exceed this size? If so and you cant cut it down to just what we need to help you out then yes, you can email. I'll send you a PM.

  • Re: Modify code to transfer data to template


    I got it figured out!!


    For some odd reason this is working...


    Code
    addme.Offset(0, 1) = Me.lstConstructionRetail.List(X, 1)
             addme.Offset(0, 2) = Me.lstConstructionRetail.List(X, 2)
             addme.Offset(0, 7) = Me.lstConstructionRetail.List(X, 3)



    Thank you so much for your help! I really appreciate the time you took for me.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!