Adding lines formula?

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
528
Office Version
  1. 365
Platform
  1. Windows
How to Add a certain line after each existing line with numbering?
like let's say this is the lines:

6, 7, 8, 9, 10, 11
12, 13, 14, 15, 16, 17
18, 19, 20, 21, 22, 23

and i want to add after each line the next phrase with a number, like this:
6, 7, 8, 9, 10, 11
New line (#1);
12, 13, 14, 15, 16, 17
New line (#2);
18, 19, 20, 21, 22, 23
New line (#3);

and so on...
can it be done in excel?
 
You are welcome!

Note that I re-marked the first reply as the solution, as that has most of the "nuts and bolts" of the code needed (so if anyone in the future was looking for how to do this, that post would be the most helpful). My second post was just a small amendment to the original code.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
follow up question, apparentlyi forgot something
is there similar way to add a new cell before the first one which will contain
int[] arr1 = {

cause right now i have all one's=1's

int[] arr1 = {1, 2, 3, 4};
listArr.add(arr1);
int[] arr1 = {5, 6, 7, 8,};
listArr.add(arr2);

and i need to incremental all by 1
 
Upvote 0
follow up question, apparentlyi forgot something
is there similar way to add a new cell before the first one which will contain
int[] arr1 = {

cause right now i have all one's=1's

int[] arr1 = {1, 2, 3, 4};
listArr.add(arr1);
int[] arr1 = {5, 6, 7, 8,};
listArr.add(arr2);

and i need to incremental all by 1
I am a little confused by your post, since you are referencing arrays, and we are not using arrays in the code in this thread anywhere.

If you want to simply want to insert the first row above the first entry, see if this does what you want:
VBA Code:
Sub MyInsertRows()

    Dim lr As Long
    Dim i As Long
    Dim ctr As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through data
    For i = 0 To lr
        ctr = ctr + 1
        Rows(i * 2 + 1).Insert
        Cells(i * 2 + 1, "A") = "New line (#" & ctr & ");"
    Next i
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
a friend is doing me a favor in java, since i don't know any code,
so when he stuck with numbering with the above problem he asked me to do it
then give him back the complete file

but i'm asking help from you guys/girls just to know if it was possible to do in excel
(tried googling it, try replace in word and notepad++ and nothing)

for the matter in hand, i need to be able to add a cell in the same line as the numbers and before them
with incremental them by 1, as shown in the example below

before:
1464.xlsx
ABCDEF
1123456
2789101112
גיליון1

after:
1464.xlsx
ABCDEFG
1123456
2int[] arr1 = {123456
3789101112
4int[] arr2 = {789101112
גיליון1
 
Upvote 0
a friend is doing me a favor in java, since i don't know any code,
so when he stuck with numbering with the above problem he asked me to do it
then give him back the complete file

but i'm asking help from you guys/girls just to know if it was possible to do in excel
(tried googling it, try replace in word and notepad++ and nothing)

for the matter in hand, i need to be able to add a cell in the same line as the numbers and before them
with incremental them by 1, as shown in the example below

before:
1464.xlsx
ABCDEF
1123456
2789101112
גיליון1

after:
1464.xlsx
ABCDEFG
1123456
2int[] arr1 = {123456
3789101112
4int[] arr2 = {789101112
גיליון1
That appears to be quite different than your original question.
So you should post it to a new thread, so it appears as a new, unanswered question, and others will see it too.
 
Upvote 0
you are right,
but now i got help with a script in notepad++ and problem solved
next time i'll probaly open a new thread
thanks!
 
Upvote 0

Forum statistics

Threads
1,222,148
Messages
6,164,234
Members
451,881
Latest member
John kaiser

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top