Add a variable number of rows based on a checkbox
Dzen
-
Dzen -
Dzen -
Hello,
I would like to create a macro that automatically generates a number of rows in a table based on a cell where I will enter the number.
Another question, is it possible to automatically create, with VBA, a vertical addition of cells in a column? This way, I could add a different number in each column, and if possible, with text customization. Then, the end user could fill them in.
I hope my explanation is sufficient. I should mention that I am a complete beginner in programming.
Thank you for your help.
Configuration: Macintosh / Chrome 87.0.4280.67
I would like to create a macro that automatically generates a number of rows in a table based on a cell where I will enter the number.
Another question, is it possible to automatically create, with VBA, a vertical addition of cells in a column? This way, I could add a different number in each column, and if possible, with text customization. Then, the end user could fill them in.
I hope my explanation is sufficient. I should mention that I am a complete beginner in programming.
Thank you for your help.
Configuration: Macintosh / Chrome 87.0.4280.67
1 answer
-
Hello,
see this:
https://docs.microsoft.com/fr-fr/office/troubleshoot/excel/macro-insert-delete-rows-columns
--
@+ The Woodpecker-
-
Go to the relevant sheet and press Alt F11 to access the sheet module
The macro will trigger on double-clicking the cell containing the number of rows to add, in this case C1
Option Explicit Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim myCell, col, ligne If Not Application.Intersect(Target, Range("C1")) Is Nothing Then Set myCell = Application.InputBox( _ prompt:="Select the starting cell", Type:=8) col = myCell.Column ligne = myCell.Row ActiveSheet.Range(ActiveSheet.Cells(ligne, col), ActiveSheet.Cells(ligne + Target.Value, col)).EntireRow.Insert End If End Sub
That's all very simple
@+ -
Good evening,
I put it in the macro, I placed it in cell D27 (the cell where I enter my value) but nothing happens. I don't know how to do it because I've never used macros. I don't understand how the "select starting cell" button works.
In fact, I'm not sure if it's clear but the number of cells to be entered in column A (of sheet 1) is found in another sheet (sheet 2 cell B1) but then, I would like to do the same thing with column B (number in sheet 2 cell D1) and do that two more times.
Thank you for your help. -
-
-