Forum Discussion
Automatically insert formatted dropdown rows as per cell value
Hello there, please see attached document with proposed solution. Hope it works as intended.
It basically reads the value of a certain cell to understand how many rows to add, then it adds that amount of rows with specific text/formula. Note that you may change your sheet name, your table name, and the cell reference indicating how many rows to add.
Martin
- dnkincMay 07, 2024Copper Contributor
Many thanks for your response Martin, however when I open the file the formulas are missing?
Is there any way that you can type the formula in here please?
MT
Nicki
- Martin_AngostoMay 07, 2024Iron Contributor
I did not use any formulas. This functionality is using VBA code (macros). To be able to see it, you just have to enable macros on this particular file. Once done, enable the "Developer" tab for the ribbon by going to File > Options > Customized Ribbon > Select Developer on the right.
Then, go to Developer > Macros and run the unique macro that it exists in the file. It automatically adds the rows based on the number value on cell B3.
If you prefer, I can share the code in here as well:
Sub AddRowsTotalAP() Dim TotalAP As ListObject Dim rowCount As Integer Dim i As Integer Set TotalAP = ThisWorkbook.Sheets("MySheet").ListObjects("TotalAP") rowCount = ThisWorkbook.Sheets("MySheet").Range("B3").Value For i = 1 To rowCount TotalAP.ListRows.Add TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 1).Value = "AP" & i TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 2).Value = "Location" TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 3).Value = "Cable" TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 4).Value = "Metres" TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 5).Value = "" TotalAP.DataBodyRange.Cells(TotalAP.ListRows.Count, 6).Formula = "=INDIRECT(""R[0]C[-2]"",FALSE)*INDIRECT(""R[0]C[-1]"",FALSE)" Next i End SubAny further comments do not hesitate to reply!