If and Else If to Insert Rows basis various Conditions

VBAEnjoi

New Member
Joined
Sep 30, 2018
Messages
33
Hello,

I have a Column with 1, 2 and 3. The number of 1s, 2s and 3s can vary.
Also there are 6 combination Options in which they can appear, grid below.
I need to insert Rows after last 1 and last 2. If the result is only 3 Option F
below I need to proceed with the next step.
Options123
AYesYesYes
BYesYesNo
CYesNoNo
DNoYesYes
ENoYesNo
FNoNoYes

<tbody>
</tbody>

Tried using If, Then and ElseIf however it stops at the first condition if that is not met.
 
Last edited:
when you insert a row between 1 and 2 in A another column could be 2,2,2, blank cell, 3

in such a case would insertion of blank row be between 2 and blank or between blank and 3 ?
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
1
1this macro did it
1
1Sub Macro4()
'
2' Macro4 Macro
2' Macro recorded 14/10/2018 by bob
'
3
3'
3 For k = 1 To 7
For j = 2 To 100
4 Sheets(k).Select
4 If Cells(j, 1) = "" Then GoTo 200
4 If Cells(j, 1) = Cells(j - 1, 1) + 1 Then GoTo 50 Else GoTo 100
50 Cells(j, 1).Select
5Selection.EntireRow.Insert
5100 Next j
200 Next k
6Sheets(1).Select
6 End Sub
7
7
7
original data
1
1
1
1
2
2
3
3
3
4
4
4
5
5
6
6
7
7
7

<colgroup><col width="64" span="16" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Hello I tried this code from another thread and it works. Thanks for your responses.

Sub InsertRow1()
Dim i As Long, x As Long, y As Long


With ActiveSheet
i = 1
Do While .Cells(i, 1) <> ""
x = .Cells(i, 1)
y = .Cells(i + 1, 1)

If y <> x Then
.Rows(i + 1).Insert
i = i + 1
End If
i = i + 1


Loop
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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