Insert new row, help

Babi_mn

New Member
Joined
Oct 4, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have 23019 row in my B column, and some of them are blank.
I want to add new blank row below each and every row except blank cells. Please help
PS i attached screenshot below (Column A is just numeric orders, ignore it please)
 

Attachments

  • Blank row.png
    Blank row.png
    79.4 KB · Views: 9
OK, see if this does what you want. If it doesn't, then I'll need to see a before-and-after sample before I can progress any further.
VBA Code:
Option Explicit
Sub Insert_Rows_V2()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<-- *** Change to actual sheet name ***
    Dim LRow As Long, LCol As Long, i As Long, j As Long
    LRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
    LCol = ws.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column + 1
   
    Dim a, b
    a = ws.Range(ws.Cells(2, 1), ws.Cells(LRow, 1))
    ReDim b(1 To UBound(a, 1), 1 To 1)
    For i = 1 To UBound(a, 1) ' - 1
            b(i, 1) = j + 1
            j = j + 1
    Next i
    ws.Cells(2, LCol).Resize(UBound(b, 1), 1).Value = b
    LRow = ws.Cells(Rows.Count, LCol).End(xlUp).Row + 1
    ws.Cells(LRow, LCol).Resize(UBound(b, 1), 1).Value = b
   
    LRow = ws.Cells(Rows.Count, LCol).End(xlUp).Row
    ws.Range(ws.Cells(2, 1), ws.Cells(LRow, LCol)).Sort Key1:=ws.Cells(2, LCol), _
    order1:=xlAscending, Header:=xlNo
    ws.Columns(LCol).EntireColumn.ClearContents
    Application.ScreenUpdating = False
End Sub
not working, showing random numbers sir
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this on a copy of your data.

Make sure that the sheet is active.


VBA Code:
Private Sub subInsertBlankRow()
Dim i As Integer
Dim lngLastRow  As Long
   
    With ActiveSheet
        lngLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    End With
       
    For i = lngLastRow To 2 Step -1
        If Len(Cells(i, 2).Value) > 0 Then
            Cells(i, 2).Offset(1, 0).EntireRow.Insert
        End If
    Next i

End Sub
i did but cant run this module
 
Upvote 0
When I run the code from post # 9, the data goes from this:
Insert rows.xlsm
AB
1HDR1HDR2
214
322
431
542
652
764
871
982
1091
11105
1211
13123
14131
15149
16155
17166
18172
19182
20194
2120
2221
23222
24237
25241
26255
Sheet1


To this:
Insert rows.xlsm
AB
1HDR1HDR2
214
3
422
5
631
7
842
9
1052
11
1264
13
1471
15
1682
17
1891
19
20105
21
2211
23
24123
25
26131
27
28149
29
30155
31
32166
33
34172
35
36182
37
38194
39
4020
41
4221
43
44222
45
46237
47
48241
49
50255
Sheet1


If this is not correct, then you need to explain what it should look like.
 
Upvote 0

Forum statistics

Threads
1,215,655
Messages
6,126,054
Members
449,283
Latest member
GeisonGDC

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