Inserting Rows

pinkpanther6666

Board Regular
Joined
Feb 13, 2008
Messages
194
Office Version
  1. 365
Platform
  1. Windows
All

In Column C starting at C1 and going downwards i have the numbers 1 to 100 but some numbers are missing

ie

1
2
3
5
6
7
8
9
15
19
23
56
89
99
100


Could somebody help me write some code to insert the missing rows and that row number in Column C



Many thanks in advance



Steve
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this out:

Code:
Public Sub FixRowNumbers()
Dim i   As Long, _
    LR  As Long
    
Application.ScreenUpdating = False
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    Do Until Range("C" & i - 1).Value = Range("C" & i).Value - 1
        Rows(i).Insert Shift:=xlDown
        Range("C" & i).Value = Range("C" & i + 1).Value - 1
    Loop
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
Code:
Sub turtleofdoom()

Dim i As Integer
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
For i = 1 To 100

    If Range("C" & i) <> i Then
        Rows(i).Insert
        Range("C" & i) = i
    End If

Next i
 
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
 
End Sub
 
Upvote 0
All,


Many thanks for your quick replies, i will try them in a bit but all looks good


Many thanks again



Steve
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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