Macro: Insert row if the sum of values of a column is ≠ 0

Earlgrey79

New Member
Joined
Feb 10, 2022
Messages
1
Office Version
  1. 2021
Hello, I'm a complete newbie to Macros and VBA, and I was wondering if someone could help me with a Macro that I need for a template sheet for accounting entries.

What I need is a macro that automatically inserts a row below only if the sum of "Importe" (column D) is not 0. (If it equals 0, nothing should be done).

For example, starting from here:

Cuentamayor
CentroAuxiliarImporteD/HDESRef1Ref2Ref3Ref4ObraMonImporteMEDescripción
43007099900000770035000,00HAAT22001189
4330008600000077003-4000,00HAAT86010016
4330008600000077003-1100,00HAAT86010018

(Here, the sum of "Importe" column is -100,00)


I need a new row that always looks like this:

CuentaMayorCentroAuxiliarImporteD/HDESRef1Ref2Ref3Ref4ObraMonImporteMEDescripción
70150099000 value that makes the sum = 0HAATAJUSTE

"Importe" (Column D) has to show a value that makes the sum equal 0. In this example, it should show 100,00.
The rest of the values should always be "701500" for column A, "99000" for column B, blank for Column C, "H" for column E, "AAT" for column F and "AJUSTE" for column G


So it would look like this:


Cuentamayor
CentroAuxiliarImporteD/HDESRef1Ref2Ref3Ref4ObraMonImporteMEDescripción
43007099900000770035000,00HAAT22001189
4330008600000077003-4000,00HAAT86010016
4330008600000077003-1100,00HAAT86010018
70150099000100,00HAATAJUSTE

Being able to do to this would save me a lot of time (that I could spend on working more, lol), so I'd be very grateful.

Thank you!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,491
Messages
6,125,099
Members
449,205
Latest member
ralemanygarcia

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