How do I inserts a calculated number of blank rows when data changes?

%3CLINGO-SUB%20id%3D%22lingo-sub-1812678%22%20slang%3D%22en-US%22%3EHow%20do%20I%20inserts%20a%20calculated%20number%20of%20blank%20rows%20when%20data%20changes%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1812678%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20printing%20some%20price%20tags%20from%20an%20excel%20spreadsheet.%20On%20the%20spreadsheet%20each%20row%20has%20store%20code%2C%20product%20and%20the%20sell%20price.%20In%20column%20A%20is%20a%20code%20for%20a%20store%2C%20in%20column%20B%20is%20the%20product%20and%20in%20Column%20C%20is%20the%20price.%20My%20question%20is%20this%2C%20when%20the%20store%20code%20changes%20from%20001%20to%20002%20for%20example%2C%20I%20would%20like%20excel%20to%20insert%20blank%20rows%20so%20I%20can%20separate%20each%20stores%20products.%20That's%20pretty%20straight%20forward%2C%20but%20the%20problem%20I%20have%20is%20that%20I'm%20printing%206%20tickets%20per%20sheet%2C%20and%20the%20number%20of%20products%20per%20store%20differ%20so%20I%20want%20excel%20to%20look%20at%20how%20many%20rows%20there%20are%20per%20store%20(ie%20the%20code%20in%20column%20A)%2C%20then%20work%20out%20how%20many%20blank%20inserted%20rows%20are%20needed%20to%20bring%20that%20up%20to%20a%20multiple%20of%206.%20That%20way%2C%20no%20sheet%20will%20have%20two%20stores%20tickets%20on%20the%20same%20sheet.%20For%20example%2C%20if%20there%20are%2058%20rows%20of%20products%20for%20store%20code%20001%2C%20then%20Excel%20will%20know%20to%20insert%202%20blank%20rows%20to%20bring%20that%20upto%2060%20rows%20in%20total.%20It%20will%20mean%20that%20the%20products%20for%20store%20002%20will%20start%20on%20the%20next%20printed%20sheet.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1812678%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1812864%22%20slang%3D%22de-DE%22%3ESubject%3A%20How%20do%20I%20inserts%20a%20calculated%20number%20of%20blank%20rows%20when%20data%20changes%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1812864%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F843707%22%20target%3D%22_blank%22%3E%40Floatyman%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EHere%20is%20an%20example%20as%20a%20starting%20point%20where%20you%20can%20pray%20how%20many%20lines%20you%20would%20like%20to%20insert%20each%20time.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EPassword%3A%20Floatyman%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1812910%22%20slang%3D%22de-DE%22%3ESubject%3A%20How%20do%20I%20inserts%20a%20calculated%20number%20of%20blank%20rows%20when%20data%20changes%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1812910%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F843707%22%20target%3D%22_blank%22%3E%40Floatyman%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3E%3CSPAN%20class%3D%22%22%3EHere%20is%20an%20example%20as%20an%20approach%2C%3C%2FSPAN%3E%20where%20you%20can%20select%20how%20many%20lines%20you%20would%20like%20to%20insert%20each%20time.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EPassword%3A%20Floatyman%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1817492%22%20slang%3D%22en-US%22%3EBetreff%3A%20How%20do%20I%20inserts%20a%20calculated%20number%20of%20blank%20rows%20when%20data%20changes%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1817492%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3BThanks.%20%26nbsp%3BHow%20did%20you%20do%20this%3F%20Was%20it%20using%20Macros%20and%20if%20so%20how%20do%20I%20do%20the%20same%3F%20%26nbsp%3BPlease%20explain%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eregards%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I'm printing some price tags from an excel spreadsheet. On the spreadsheet each row has store code, product and the sell price. In column A is a code for a store, in column B is the product and in Column C is the price. My question is this, when the store code changes from 001 to 002 for example, I would like excel to insert blank rows so I can separate each stores products. That's pretty straight forward, but the problem I have is that I'm printing 6 tickets per sheet, and the number of products per store differ so I want excel to look at how many rows there are per store (ie the code in column A), then work out how many blank inserted rows are needed to bring that up to a multiple of 6. That way, no sheet will have two stores tickets on the same sheet. For example, if there are 58 rows of products for store code 001, then Excel will know to insert 2 blank rows to bring that upto 60 rows in total. It will mean that the products for store 002 will start on the next printed sheet.

8 Replies
Highlighted

@Floatyman 

Here is an example as an approach, where you can select how many lines you would like to insert each time.

Passwort: Floatyman

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

Highlighted

@Nikolino Thanks.  How did you do this? Was it using Macros and if so how do I do the same?  Please explain

 

regards,

 

Highlighted

@Floatyman 

Here is the code...is in German vba commands.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim zeilenanzahl As Long
Dim x As Integer
Dim i As Integer
x = 1
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If Target.Column = 1 And Target.Row > 2 Then
Worksheets("2021").Unprotect Password:="Floatyman"
On Error GoTo Notausgang
zeilenanzahl = InputBox("How many rows?", "Insert rows")
With ActiveCell
For i = 1 To zeilenanzahl
If ActiveCell = "" Then
.EntireRow.Copy
.EntireRow.Offset(x, 0).Insert shift:=xlDown
.EntireRow.Offset(x, 0).PasteSpecial
ActiveCell = 1
.EntireRow.Offset(x, 0).SpecialCells(xlCellTypeConstants).ClearContents
Else
.EntireRow.Copy
.EntireRow.Offset(x, 0).Insert shift:=xlDown
.EntireRow.Offset(x, 0).PasteSpecial
.EntireRow.Offset(x, 0).SpecialCells(xlCellTypeConstants).ClearContents
ActiveCell.Offset(-x, 0).Select
End If
x = x + 1
Next i
.Offset(1, 0).Select
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Sheets("2021").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowFormattingCells:=True, AllowFormattingRows:=True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowSorting:=True, AllowFiltering:=True, _
Password:="Floatyman"
Notausgang:
Cancel = True
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Sheets("2021").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowFormattingCells:=True, AllowFormattingRows:=True, AllowFormattingColumns:=True, _
AllowInsertingColumns:=True, AllowSorting:=True, AllowFiltering:=True, _
Password:="Floatyman"
End If
End Sub

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

 

Nikolino

I know I don't know anything (Socrates)

Highlighted
Huge apologies but I'm lacking the knowledge here. I paste the code into Visual Basic in the developer ribbon, and run it but nothing seems to happen.

How do I run the code please?
Highlighted
ALT + F11

Select the sheet
paste the code on the right side
Safe sheet

...and run.

If you can't do it with my instructions (I'm not the best at explaining :), you can send with a file (without sensitive data, please) and we will try to finish it for you. A service of the house

Ps. Please just be patient, could maybe (which I hope not) take a little longer, but maybe only if there is work to be done.

Nikolino
I know I don't know anything (Socrates)






Highlighted
But if you mean how to run this code in the worksheet. Then click from cell A2 (only possible in column A) and a message window appears where you can insert the number of rows. If it is, then sorry the translation is not the best Thank you for your understanding and patience Nikolino I know I don't know anything (Socrates)
Highlighted

@Nikolino Thank you for your help.  I paste the code in and Excel asks me to name and create a Macro, which I do.  Then Run, but see no difference so I must be doing something wrong.

 

Attached is a file.  In column A, when the code changes I would like 10 blank rows (or ideally a number rounded to up a multiple of 6) to be inserted to separate these codes into groups on the sheet.

 

regards

Highlighted

@Floatyman 

 

Ready to use!

 

Simply left double-click on column A (from A2) with the mouse and a user form will appear. There you enter how many lines you want and they will appear.

 

Tested and it works for me without problems.

 

I wish you continued success with Excel (the coolest invention since chocola... uh ... Microsoft! :)))

And keep asking here - I just taught myself Excel with the help of this forum :).

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here