Insert rows in excel based on specific Conditions VBA macro

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
205
Office Version
  1. 2019
Platform
  1. Windows
I have a excel sheet where there are many Balance rows. In Column A there are Demand Collection Balance Rows, where Balance = Demand - Collection.

So there are multiple Balance Rows are there in that sheet. Column FGHIJ are inter related.

I want a macro that if in any Balance row there are negative value in FGHI column followed by any positive value a new row will be insert above the balance row.

for example

1. there is a negative value in F column -100 and positive value in either G or H or I or J column
2. there is a negative value in G column -100 and positive value in either H or I or J column
3.there is a negative value in I column -100 and positive value in either I or J column
4.there is a negative value in I column -100 and positive value in J column

In the above situation a blank row should be insert over the Balance row

If there is any positive value in F column but negative value in G column then row should not be insert.

example 40 -100 0 0 0 in FGHIJ column

Another example 40 -100 20 30 40

Here a new row should be inserted because the negative value is followed by positive values in the column

A new row should insert only if a negative value is followed by a positive value in in F G H I J column serially from left to right.

I want a VBA macro to insert rows above the Balance Row where the condition fulfills


Kindly check the image to understand better, in the blue marked columns a new row should insert as it fulfills the criteria but in the yellow marked columns it should not as the negative value doesn't followed by a positive value.
byadjustment.JPG
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,222,827
Messages
6,168,482
Members
452,192
Latest member
FengXue

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