• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel Table: VBA to create a row in the first Table Row & populate the column sequence

inddon

Member
Hello There,

I have an excel table and a button (Insert row) button linked to it.

When the User clicks on the button, a row should be created in the first row of the table. There is a sequence column 'Invoice Number'. As soon as the new row is the column should get a value (previous max row Invoice Number + 1).

Could you please advice how this can be done using VBA?

Attached is the sample workbook 1 for your reference.

Look forward to hearing from you.


Thanks in advance
Don
 

Attachments

  • Sample Workbook 1.xlsm
    19 KB · Views: 3
Hi !

Just start with activating the Macro Recorder and operate manually :
you will get your own code base, a good way to learn !
Post here the generated code if you need any optimization …
 
Hi Marc,

Thank you for your reply.

I tried to record the macro as below:

Code:
Sub Macro1()

' Macro1 Macro
    Range("J21").Select
    Selection.ListObject.ListRows.Add (1)
End Sub


Thought it would generate the table name selection and do the insert row.

It should select the table name and the first row selection and insert row, but don't know how this can be done in code.


Regards,
Don
 
Last edited by a moderator:
Like you proceed from the first cell, the name is not necessary :​
Code:
Sub Macro1()
    [J21].ListObject.ListRows.Add 1
    [J21].Value = [J22].Value + 1
End Sub
 
Back
Top