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:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I need to insert Rows after last 1 and last 2

you have 6 rows at present - when do you want to insert another row - and if it is the last row you are populating a row, not inserting it - are you creating combinations ?
 
Upvote 0
Hello

I have dynamic number of rows. Each of them could have either value 1,2 or 3. In the below e.g. I would like to insert row at A4 and A6

A1 = 1
A2 = 1
A3 = 1
A4 = 2
A5 = 2
A6 = 3
 
Upvote 0
1101
1102
1103
2204
2205
3
where there is a 1 then 100 plus row number
where there is a 2 then 200 plus row number
=large(C1:C10,1) finds 103
say the 103 is in J1 then K1 is J1 minus 100 plus 1 then a macro can use that
cells(1,11).select
code to insert new row
repeat for col D

<colgroup><col width="64" span="11" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Hi do you want me to add new columns?
Can I not do it in the same column and a simpler code

1101
1102
1103
2204
2205
3
where there is a 1 then 100 plus row number
where there is a 2 then 200 plus row number
=large(C1:C10,1) finds 103
say the 103 is in J1 then K1 is J1 minus 100 plus 1 then a macro can use that
cells(1,11).select
code to insert new row
repeat for col D

<tbody>
</tbody>
 
Upvote 0
I need a macro. I need to know how to provide the If Then Else Condition with the above 6 combinations
 
Upvote 0
Hello - Await your revert. Thanks. Listing below the possible options.
Don't go with the A,B, C etc. listed earlier.

ABCDEFG
1111223
1111223
1121223
221223
2233
233
3
3

<tbody>
</tbody>


<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Last edited:
Upvote 0
ABCDEFG
1111223
1111223
1121223
221223
2233
233
3
3

<tbody>
</tbody>

Let me take each options above and explain
A - Want to insert a row between 1 and 2 and 2 and 3
B - Don't have to do anything since there is only one number
C - Want to insert a row between 1 and 2
D - Want to insert a row between 1 and 3
E - Want to insert a row between 2 and 3
F - Don't have to do anything since there is only one number
G - Don't have to do anything since there is only one number
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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