# EXCEL VBA for Mass Balance

#### meschackime

##### New Member
[h=4]Good day community,

Would you help to write a vba code for following Mass balance & Data Reconciliation[/h]The data reconciliation problem is solved using the method of Lagrange Multipliers.
Let’s denote the vector of measurements as M, whose elements are the measurements of each mass variable. And let’s denote the corresponding vector of percent uncertainties as UP. Then, the vector of absolute uncertainties UA is given by equation 4:
UA = UP⊗M
where the operator “⊗” means an element-wise multiplication.
The reconciliation matrix is given by equation 5:
H(Nm + Nc) x (Nm + Nc) = [ DCT
C0 ]

where: D is a Nm×Nm diagonal matrix whose k-th diagonal element is given by: dkk = 2/(UA(k))2. C is the Nc×Nmnodal matrix. 0 is a Nc×Nc null matrix.

The solution is given by equation 6:
S = H-1 x M
where the first Nm elements of the vector S are the reconciled measurements given by equation 7:
R(k) = S (k) ǀ 1 ˂ k ˂ Nm
and the remaining elements in S are the Lagrange multipliers given by equation 8:
L(k) = S(k) ǀ Nm + 1 ˂ k ˂ Nm + Nc

The vector of reconciliation adjustments, which are the corrections made on the original values, are given by equation 9:
A = R – M
Best regards,

Meschac

### Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

#### Joe4

Welcome to the Board!

This looks like homework or some other type of class assignment. Note that it is the policy of the board not to do your homework/assignments for you, but we may be willing to give you some hints and nudge in the right direction.

What don't you show us what you have done so far on it, and let us know what part is giving you trouble, and maybe someone can help point you in the right direction?

#### meschackime

##### New Member
This is not part of any class assignment. It personal work that I am doing and thought I could do it using VBA. I will submit next the code that I cam with.

Thanks

#### Joe4

OK, its just that we do see that a bit, and since the font was different than your font at the top, it looked like it was copied and pasted from somewhere else.

You probably can do it with VBA, though it will probably take a bit of work. For most of us here, the obstacle would be understanding the math behind it. So unless someone very familiar with these concepts stumble upon this question, your best bet for getting help may be to break it down into small components, do what you can, and post specific, individual questions. Try to explain it in such a way that the person helping does not need to understand all the concepts behind it to help you. If you can provide the knowledge, we may be able to provide the VBA.

#### meschackime

##### New Member
Many thanks. I will break it in small questions.