Excel - Tables - Identifying the Next Row

Asked

Viewed 1,326 times

1

good afternoon. This is my first question here. I thank those who can guide me.

I made a spreadsheet with some tables (tab "Home page", "Format as table"). Then, I made a VBA to clean this table and insert new information from a text file. I was using a feature that is to identify the row where the table is through the Range command("Table name").row. From there, I incremented a counter that would always give me the number of the next line. Look below:

    ...
    Application.Goto Reference:="NomeDaTabela"
    PróximaLinhaDaTabela = Range("NomeDaTabela").Row
    For X = 1 To 50 'Simulando os registros de um array
        ActiveSheet.Cells(PróximaLinhaDaTabela, 1) = X
        PróximaLinhaDaTabela = PróximaLinhaDaTabela + 1
    Next
    ...

It turns out that I am not actually "controlling" the next row of the "Databela" table. I am controlling the next line of the spreadsheet ("Activesheet"). When I try to add a new row in the table through the Range("Table name) command. Insert, it inserts a row at the beginning of the table, just below the header. I would like him to insert at the end, after the other rows of the table that are already filled. And that I could reference this new line to add values. If I try to use the Range("Databela") command. Cells(Nextmetadatabela, Column), it uses the table position plus the number of rows reported. That is, the Range("Dataname") "knows" command where the table is located. I don’t know how to reference.

Has anyone ever done anything like this?

From now on, thank you.

1 answer

0


Welcome!

If you are looking for how to add a row to an object as a predefined table the code will look something like this:

Set myNewRow = ActiveWorkbook.Worksheets(1).ListObject(1).ListRows.Add

In this case you should add a line below.

I hope I’ve helped!

Reference

  • Thank you, Evert. That’s exactly what I was looking for. I did some research and I see that I will have to change my code to properly treat these tables. I was using "Range", but I think I should treat it as "Listobject". Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.