code to find account and sum up values
I am trying to design a code that operates on two sheets in Excel. On the first sheet is an account number and on the second sheet is the same account number with itemized values, for example:
sheet 1:
account # --------------- Total
115
116
117
118
sheet 2:
account # ------- amount
115 -------------- 10
115 -------------- 20
115 -------------- 30
116
Now I need to write a code that searches sheet 2 for all itemized accounts, lets say account 115 and sums up all those values, here it would be 60 and then places that total under account 115 on sheet 1, then it needs to switch to account 116 and do the same process.
what I have developed as psuedocode is:
sub organize()
worksheets("sheet 1 Acct #").Range("G1")=n <G1 is sheet 1 account #>
n+1=m <this is to always search the next account number>
<I know I will need another equation to search for the next account>
find m
worksheets("sheet 2 Acct #").Range("B1")=p <B1 is sheet 2 account #>
p+1=q
if worksheets("sheet 2 Acct #").Range(q) = worksheets("sheet 1 Acct #").Range("m")
Next Cell
else sum() <if only 1 cell contains a value it would be entered on sheet 1, not sure how to match corresponding cell>
Do until worksheets("sheet 2 Acct #").Range("q") <> worksheets("sheet 1 Acct #").Range("m")
then sum() <not sure how to match corresponding cell and create a range>
end sub
Any help would be appreciated in fleshing out the psuedocode or ideas.
thanks
|