I need help to change a Do While Not Loop

Andries

Board Regular
Joined
Feb 3, 2011
Messages
127
Hi

I
I am currently using this code but I need to change it but I don't know how..I am a beginner at this. I don't want to insert the entire row but only range "A:I"


"Do While Not IsEmpty(cell.Value)
If cell.Value > 1 Then
Range(cell.Offset(1), cell.Offset(cell.Value - 1)).EntireRow.Insert
Range(cell, cell.Offset(cell.Value - 1, 1)).EntireRow.FillDown
End If
Set cell = cell.Offset(cell.Value)
Loop"

Thank you
Dries
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Again

I have info in Column A to I, Column I has a number which is variable. Based on what the value is in column I for example 12. the code must Duplicate this info which is only in column A to I for another 11 times.

This code is working but I don't want to copy the entire row only the info in Columns A to I. The info in Column J and further on must not be duplicated

Set Cell = .Range("I17")
Do While Not IsEmpty(Cell.Value)
If Cell.Value > 1 Then
Range(Cell.Offset(1), Cell.Offset(Cell.Value - 1)).EntireRow.Insert
Range(Cell, Cell.Offset(Cell.Value - 1, 1)).EntireRow.FillDown
End If
Set Cell = Cell.Offset(Cell.Value)
Loop
 
Upvote 0
Hi JoeMo

Have I changed this correctly? because instead of copying the info in Columns A to I it copies Info from I to Q

Set Cell = .Range("I17")
Do While Not IsEmpty(Cell.Value)
If Cell.Value > 1 Then
Range(Cell.Offset(1), Cell.Offset(Cell.Value - 1)).Resize(, 9).Insert
Range(Cell, Cell.Offset(Cell.Value - 1, 1)).Resize(, 9).FillDown
End If
Set Cell = Cell.Offset(Cell.Value)
Loop
End With
End Sub
 
Upvote 0
Another way:
Code:
    Dim cell        As Range
 
    Set cell = Range("I17")
 
    Do Until IsEmpty(cell.Value)
        If VarType(cell.Value2) = vbDouble Then
            If cell.Value > 1 Then
                cell.Offset(1).Resize(cell.Value - 1).EntireRow.Range("A1:I1").Insert
                cell.EntireRow.Range("A1:I1").Resize(cell.Value).FillDown
            End If
 
            Set cell = cell.Offset(cell.Value)
        End If
    Loop
 
Upvote 0
You didn't say where cell was located in your original post so I assumed it was column A. Changes:
Code:
Range(cell.Offset(1), cell.Offset(cell.Value - 1)).Offset(0, -8).Resize(, 9).Insert
Range(cell, cell.Offset(cell.Value - 1, 1)).Offset(0, -8).Resize(, 9).FillDown
 
Upvote 0
Hi JoeMo

I have tried the code but it appears that there is something wrong. This is my list of info and please see the second table what it should look like.


Excel Workbook
ABCDEFGHIJ
130-May-11XDLM501TA24240O/B11GREEN-1-1
230-May-11XMHC201TB30180414CLOSED17GREEN-1-2
330-May-11XMMH211TC130180414CLOSED20GREEN-1-3
Sheet3



Excel Workbook
ABCDEFGHIJ
130-May-11XDLM501TA24240O/B11GREEN-1-1
230-May-11XDLM501TA24240O/B11GREEN-1-2
330-May-11XDLM501TA24240O/B11GREEN-1-3
430-May-11XDLM501TA24240O/B11GREEN-1-4
530-May-11XDLM501TA24240O/B11GREEN-1-5
630-May-11XDLM501TA24240O/B11GREEN-1-6
730-May-11XDLM501TA24240O/B11GREEN-1-7
830-May-11XDLM501TA24240O/B11GREEN-1-8
930-May-11XDLM501TA24240O/B11GREEN-1-9
1030-May-11XDLM501TA24240O/B11GREEN-1-10
1130-May-11XDLM501TA24240O/B11GREEN-1-11
1230-May-11XMHC201TB30180414CLOSED17GREEN-1-12
1330-May-11XMHC201TB30180414CLOSED17GREEN-1-13
1430-May-11XMHC201TB30180414CLOSED17GREEN-1-14
1530-May-11XMHC201TB30180414CLOSED17GREEN-1-15
1630-May-11XMHC201TB30180414CLOSED17GREEN-1-16
1730-May-11XMHC201TB30180414CLOSED17GREEN-1-17
1830-May-11XMHC201TB30180414CLOSED17GREEN-1-18
1930-May-11XMHC201TB30180414CLOSED17GREEN-1-19
2030-May-11XMHC201TB30180414CLOSED17GREEN-1-20
2130-May-11XMHC201TB30180414CLOSED17GREEN-1-21
2230-May-11XMHC201TB30180414CLOSED17GREEN-1-22
2330-May-11XMHC201TB30180414CLOSED17GREEN-1-23
2430-May-11XMHC201TB30180414CLOSED17GREEN-1-24
2530-May-11XMHC201TB30180414CLOSED17GREEN-1-25
2630-May-11XMHC201TB30180414CLOSED17GREEN-1-26
2730-May-11XMHC201TB30180414CLOSED17GREEN-1-27
2830-May-11XMHC201TB30180414CLOSED17GREEN-1-28
2930-May-11XMMH211TC130180414CLOSED20GREEN-1-29
Sheet3
 
Upvote 0
Hi Anybody else that can assist...it seems like Joemo is offline and I am desperate

I see that if the values in Column I is less than 11 the code is working fine but if above 11 it is not working correctly

thanks
Dries
 
Upvote 0
Try this. Note that, consistent with your example, the first cell is I1, not I17.

Code:
Sub x()
    Dim cell        As Range
 
    Set cell = Range("I1")
 
    Do Until IsEmpty(cell.Value)
        If VarType(cell.Value2) = vbDouble Then
            If cell.Value > 1 Then
                cell.Offset(1).EntireRow.Range("A1:I1").Resize(cell.Value - 1).Insert Shift:=xlShiftDown
                cell.EntireRow.Range("A1:I1").Resize(cell.Value).FillDown
                Set cell = cell.Offset(cell.Value)
            Else
                Set cell = cell.Offset(1)
            End If
        Else
            Set cell = cell.Offset(1)
        End If
    Loop
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,543
Messages
6,179,429
Members
452,914
Latest member
echoix

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