VBA - Use one column values to mount table

Asked

Viewed 64 times

2

Good morning,

I’m extracting a database with dates and number of occurrences. But for my statistical model I need to organize it in a way that only the dates appear multiplied by the number of occurrences.

Abaixo a tabela como veio

inserir a descrição da imagem aqui

I understand that I have to make a loop to store the values to then use them, I managed with this code, but I do not know how to use these values to build my table, if anyone can help me, please:

Sub table_array()

Dim myTable As ListObject
Dim myArray As Variant

Set myTable = ActiveSheet.ListObjects("Tabela1")
myArray = myTable.DataBodyRange

'Loop through each item in the Table Array (displayed in Immediate Window [ctrl + g])


 For x = LBound(myArray) To UBound(myArray)
    Debug.Print myArray(x, 2)
          
 Next

1 answer

0

I was able to find the answer

Sub table_array()

Dim myTable As Listobject Dim myArray As Variant

'Set the table name in Excel and if necessary modify below Set myTable = Activesheet.Listobjects("Table1") myArray = myTable.Databodyrange Dim i As Date Dim Line As Integer

'Loop through each item in the Table Array (displayed in Immediate Window [Ctrl + g]) 'Line shows on which line the values will be included

Row = 2

' This function below takes the data from the table body

For x = Lbound(myArray) To Ubound(myArray)

' Find all values in column 2 and use the number found to repeat entries in column one. For Z = 1 To myArray(x, 2) Cells(Row, 6). Value = myArray(x, 1) Row = Row + 1

Next

Next

End Sub

Browser other questions tagged

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