using VBA code/macro for InputBox and then performing calculations

saadshakil

New Member
Joined
Jul 22, 2018
Messages
1
I have data set of about 6000 rows and it looks something like below:

Cost Center

<tbody>
</tbody>
Item code

<tbody>
</tbody>
Value ($)

<tbody>
</tbody>
Sales Proceeds

<tbody>
</tbody>
Proportionate Sales proceeds

<tbody>
</tbody>
HK1110S1111

<tbody>
</tbody>
2587

<tbody>
</tbody>
2,000

<tbody>
</tbody>
HK1110S1111

<tbody>
</tbody>
4152

<tbody>
</tbody>
4,000

<tbody>
</tbody>
HK1110S1111
9687

<tbody>
</tbody>
2,000
HK1110S0014
2560

<tbody>
</tbody>
10,000
HK1110S1005
2154

<tbody>
</tbody>
4,500
HK1110S1005
6781

<tbody>
</tbody>
6,000
HK1110S1117

<tbody>
</tbody>
3078

<tbody>
</tbody>
3,500
HK1110S1117

<tbody>
</tbody>
5548

<tbody>
</tbody>
4,200
HK1110S1117

<tbody>
</tbody>
8623

<tbody>
</tbody>
5,000
HK1110S1117

<tbody>
</tbody>
9012

<tbody>
</tbody>
9,800

<tbody>
</tbody>

Lets assume Column A - Cost Center is a unique Location. For eg. HK1110S1111 is Room A, HK1110S0014 is Room B and so on. Each room has Items in it which have a unique code - Column B. Column C represents the Value of items in Column B.

1) Firstly, I need to enter Sales Proceeds(D). For that cells in Column D needs to be merged according to value in Column A. Sales Proceeds are cumulative - according to Location, not Item(B) wise. Therefore D2:D4, D6:D7 and D8:D11 needs to be merged based on their correspondence values in Column A. I have already written and assigned a Command Button for this VBA code and the cells in Column D are merging perfectly.

Now I need something like InputBox which would display text from Column A and the punched valued is entered in Column D. For eg. Upon hit of Command button InputBox pops up like: "Enter Sales proceeds for HK1110S1111" and the input value is entered in correspondence cell of A2 that is D2:D4 (merged cells). The task should repeat for all Column A range (Enter Sales proceeds for HK1110S0014, Enter Sales proceeds for HK1110S0005) and so on. I would assign a Command Button to this task as Step 2 for my own reference.

2) This is Step 3 and like above I would insert a Command button for this macro/code. Here I need to do calculations in Column E. This is very critical and most important part. The Sales Proceeds (D) should be distributed to Items(B) according to proportion of their Value(C). For eg. Sales Proceeds for HK1110S1111 is $12,000 (D2:D4). Thereby:
E2 = 2000(C2)/(2000(c2)+4000(c3)+2000(c4))*12000(D2:D4)
E3 = 4000/(2000+4000+2000) * 12000
E4 = 2000/(2000+4000+2000) * 12000

Sales Proceeds for HK1110S0014 is $9,000 so:
E5 = 10000/10000 * 9000

I would really appreciate your help to automate these calculation. There are about 6000 rows and more to come and this calculation has to be performed on each row. So far I have been doing all of this manually which is resulting in mistakes and lot of time consuming.

The end result should look something like this:

Cost Center

<tbody>
</tbody>
Item code

<tbody>
</tbody>
Value ($)

<tbody>
</tbody>
Sales Proceeds

<tbody>
</tbody>
Proportionate Sales proceeds

<tbody>
</tbody>
HK1110S1111

<tbody>
</tbody>
2587

<tbody>
</tbody>
2,000

<tbody>
</tbody>
12,0003,000
HK1110S1111

<tbody>
</tbody>
4152

<tbody>
</tbody>
4,000

<tbody>
</tbody>
"6,000
HK1110S1111
9687

<tbody>
</tbody>
2,000"3,000
HK1110S0014
2560

<tbody>
</tbody>
10,0009,0009,000
HK1110S1005
2154

<tbody>
</tbody>
4,50010,0004286
HK1110S1005
6781

<tbody>
</tbody>
6,000"5714
HK1110S1117

<tbody>
</tbody>
3078

<tbody>
</tbody>
3,50045,0007,000
HK1110S1117

<tbody>
</tbody>
5548

<tbody>
</tbody>
4,200"8,400
HK1110S1117

<tbody>
</tbody>
8623

<tbody>
</tbody>
5,000"10,000
HK1110S1117

<tbody>
</tbody>
9012

<tbody>
</tbody>
9,800"

<tbody>
</tbody>


Looking forward for solutions. Thanks in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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