VBA macro to input formlas in certain locations besed on identifiers

thelad

Board Regular
Joined
Jan 28, 2011
Messages
245
Hi,

Not sure if im going to explain this correctly or over-complicating but hoping someone can help

I have a macro that copies data into an excel from column A to D. In column B will be identifiers that will drive the formulas. (date might be needed but not sure)

Example we copy in data from another location in columns A to D as below. We would like the macro to do the following:
For every identifier 0 which is in column B would like the following formulas in expense & income row:

Expense (Column E)
=SUMIFS(Sheet2!F:F,Sheet2!P:P,Sheet1!A2)
Income (Column F)
=SUMIFS(Sheet2!H:H,Sheet2!P:P,Sheet1!A2)

Then for the identifier in between the zeros would like the totals (row with identifier 0) multiplied by ratio. For example:

Cell E3 will have formula =C3*$E$2
Cell E4 will have formula = =C4*$E$2
Cell F3 will have formula = =$F$2*C3
Cell F4 will have formula = =$F$2*C4

These formulas will drag down for all identifiers for that date say 01/09/17.

Then say on 04/09/17 we will input the sumif formulas for identifier 0

Then under identifier 0 we will need to input the formulas again as above except the referenced cell will be now identifier 0 from the 04/09/17.

Does that make sense? Can macro be built for this

Example output should be as follows basing on the totals pulled in by the sumifs etc

DateIdentifierratiototalexpenseIncome
01/09/17011,734,832,798.05
-247531.15

<tbody>
</tbody><colgroup><col></colgroup>
3,131,045.77

<tbody>
</tbody><colgroup><col></colgroup>
01/09/1710.2
346,966,559.61

<tbody>
</tbody><colgroup><col></colgroup>
-49506.23

<tbody>
</tbody><colgroup><col></colgroup>
626,209.15

<tbody>
</tbody><colgroup><col></colgroup>
01/09/1720.2
346,966,559.61

<tbody>
</tbody><colgroup><col></colgroup>
-49506.23

<tbody>
</tbody><colgroup><col></colgroup>
626,209.15

<tbody>
</tbody><colgroup><col></colgroup>
01/09/1730.2
346,966,559.61

<tbody>
</tbody><colgroup><col></colgroup>
-49506.23

<tbody>
</tbody><colgroup><col></colgroup>
626,209.15

<tbody>
</tbody><colgroup><col></colgroup>
01/09/1740.4
693,933,119.22

<tbody>
</tbody><colgroup><col></colgroup>
-99012.46

<tbody>
</tbody><colgroup><col></colgroup>
1,252,418.31

<tbody>
</tbody><colgroup><col></colgroup>
04/09/1701
1,795,304,394.68

<tbody>
</tbody><colgroup><col></colgroup>
-266461.87

<tbody>
</tbody><colgroup><col></colgroup>
3,165,470.16

<tbody>
</tbody><colgroup><col></colgroup>
04/09/1710.2
359,060,878.94

<tbody>
</tbody><colgroup><col></colgroup>
-53292.374

<tbody>
</tbody><colgroup><col></colgroup>
633,094.03

<tbody>
</tbody><colgroup><col></colgroup>
04/09/1720.2
359,060,878.94

<tbody>
</tbody><colgroup><col></colgroup>
-53292.374

<tbody>
</tbody><colgroup><col></colgroup>
633,094.03

<tbody>
</tbody><colgroup><col></colgroup>
04/09/1730.2
359,060,878.94

<tbody>
</tbody><colgroup><col></colgroup>
-53292.374

<tbody>
</tbody><colgroup><col></colgroup>
633,094.03

<tbody>
</tbody><colgroup><col></colgroup>
04/09/1740.2
359,060,878.94

<tbody>
</tbody><colgroup><col></colgroup>
-106584.75

<tbody>
</tbody><colgroup><col></colgroup>
1,266,188.06

<tbody>
</tbody><colgroup><col></colgroup>
05/09/1701
1,699,286,162.05

<tbody>
</tbody><colgroup><col></colgroup>
-272588.23

<tbody>
</tbody><colgroup><col></colgroup>
3,178,645.21

<tbody>
</tbody><colgroup><col></colgroup>
05/09/1710.5
849,643,081.03

<tbody>
</tbody><colgroup><col></colgroup>
-136294.12

<tbody>
</tbody><colgroup><col></colgroup>
1,589,322.61

<tbody>
</tbody><colgroup><col></colgroup>
05/09/1720.5
849,643,081.03

<tbody>
</tbody><colgroup><col></colgroup>
-136294.12

<tbody>
</tbody><colgroup><col></colgroup>
1,589,322.61

<tbody>
</tbody><colgroup><col></colgroup>

<tbody>
</tbody>
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

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