Divide by VBA

ashani

Active Member
Joined
Mar 14, 2020
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hi

I wonder if someone could help me with this please.

- If in Column G select "social" then increase allowance by 20% of K1 for that particular day
- Also reduced equally for all other days - however the total should remain 700 in Column C.

I'd really appreciate your guidance in the attachment.

thanks

1587078618145.png
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Perhaps you can provide some sample results to illustrate?

Otherwise it's not clear which cells are impacted when you say:
- increase allowance?
- reduced equally?
 
Upvote 0
Hi
thank you for the message. I have copied 3 examples of the outcome. Hope this is ok.
Many thanks for your help again.


1587116352803.png


1587116459710.png




1587116482026.png
 
Upvote 0
Admin - no intention to bring the post up. It’s just another option if I can get any guidance.

Just thinking even if I can get any help with a formula to achieve that if VBA isn’t possible.
thanks
 
Upvote 0
This closely replicates your numbers - with some minor rounding differences. We could eliminate the helper cells and combine into one formula, but it would be ugly.

The table at the bottom shows all 8 possibilities assuming SOCIAL days are always in a single block starting on Monday.

ABCDEFGHIJK
1700
2
3100
4
5CARBS
6MON118SOCIAL
7TUE118SOCIAL
8WED117SOCIAL
9THU117SOCIAL
10FRI77
11SAT77
12SUN76
13
14
15TotalCount
16SOCIAL4704
17NON2303
18
19
20# SOCIAL -->01234567
21MON100240159131118110104100
22TUE10077158131118110104100
23WED1007777131117109104100
24THU100777777117109104100
25FRI10077777777109104100
26SAT1007676777777103100
27SUN100767676767677100
Sheet1
Cell Formulas
RangeFormula
C6:C12C6=ROUNDUP(IF(G6="SOCIAL",(C$16-SUMIF(G$5:G5,"SOCIAL",C$5:C5))/(D$16-COUNTIF(G$5:G5,"SOCIAL")),(C$17-SUMIF(G$5:G5,"",C$5:C5))/(D$17+1-COUNTIF(G$6:G6,""))),0)
C16C16=7*C$3-ROUND((COUNTBLANK(G$6:G$12))*(6*C3-IF(COUNTIF(G$6:G$12,"SOCIAL"),20%*K$1))/6,0)
D16D16=COUNTIF(G$6:G$12,"SOCIAL")
C17C17=ROUND((COUNTBLANK(G$6:G$12))*(6*C3-IF(COUNTIF(G$6:G$12,"SOCIAL"),20%*K$1))/6,0)
D17D17=COUNTBLANK(G$6:G$12)
 
Upvote 0
@StephenCrump
You are an absolute legend and amazing. Thank you so much
Last quick question -
With the same thing - is it possible to have option for "Training" with 10% allowance i.e. From dropdown menu - Social selected than 20% and if Training Selected than 10% otherwise stay as 100 ?

Thank you once again - it's really going to help me with my assignment.
 
Upvote 0
... it's really going to help me with my assignment.

Assignment?! What subject are you studying?

So far, I have assumed that the "rule" is:
If any day of the week is SOCIAL, Carbs for each non-SOCIAL day = (700-240)/6 = 76.7 approx.

That doesn't necessarily make sense, but it does replicate your numbers.

Can you explain the "rule" for TRAINING, and illustrate with some examples, including (if this is permitted?) variations with SOCIAL, TRAINING and blank?
 
Upvote 0
On looking again, I also realise we can simplify:

C16: =7*C3-H17
C17: =(C3-IF(COUNTIF(G$6:G$12,"SOCIAL"),20%*K1/6))*COUNTBLANK(G$6:G$12)
 
Upvote 0
@StephenCrump

Hi Sir,

Thank you once again, honestly I couldn't thank enough for your help. I'm currently studying Maths with actuarial science.
In regards to' Training' so it will work exactly the same way as 'Social' so instead of 'Social' if someones selects Training and the calculation will work on 10% of 700.

If any day of the week is SOCIAL, Carbs for each non-SOCIAL day = (700-240)/6 = 76.7 approx.
If any day of the week is TRAINING, Carbs for each non-TRAINING day = (700-170)/6 = 88.33 approx.

I have attached the example in the sheet - there are 3 options, SOCIAL, TRAINING & WORK. Social will be 20% of 700, Training will be 10% of 700 and Work will remain as whatever the number is- no change.

Once again thank you so much - honestly if you were local I would have brought you something to say thank you :)
 

Attachments

  • Screenshot 2020-04-18 at 14.07.46.png
    Screenshot 2020-04-18 at 14.07.46.png
    115.5 KB · Views: 15
  • Screenshot 2020-04-18 at 14.41.12.png
    Screenshot 2020-04-18 at 14.41.12.png
    117.7 KB · Views: 15
  • Screenshot 2020-04-18 at 14.30.13.png
    Screenshot 2020-04-18 at 14.30.13.png
    230.3 KB · Views: 12
  • Screenshot 2020-04-18 at 14.31.51.png
    Screenshot 2020-04-18 at 14.31.51.png
    130.2 KB · Views: 12
Upvote 0
I have given you one way to round a total into integer amounts, which in its simplest form is:

ABCDEFG
1
2
3
4
5
6MON118X
7TUE118X
8WEDSomethingElse
9THU117X
10FRISomethingElse
11SAT117X
12SUNSomethingElse
13
14
15Total
16X470
Sheet1
Cell Formulas
RangeFormula
C6:C12C6=IF(G6="X",ROUNDUP((C$16-SUMIF(G$5:G5,"X",C$5:C5))/COUNTIF(G6:G$12,"X"),0),"SomethingElse")

For your assignment, all you need to do is generalise to allow for Y and Z.
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,652
Members
449,462
Latest member
Chislobog

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