VBA newbie- need help

ljkeefe

New Member
Joined
Jan 14, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,
I was initially tasked with creating a formula for this particular operation. However, the more I researched the more I realized that a formula alone would not produce the function that is being asked for. I'm interested in learning VBA but for the sake of time, I'd like to get this to my department without further delay. I just don't know anything about coding. Help with VBA would be great or even a referral to some sources to help me would be great as well.
Here's the scenario:
We have a truck with two tanks of the same material, CCB. We would like to track the quantity and cost of the CCB used in a season. The truck is set up to draw from Tank 2(column K) and once depleted it moves on to Tank 1(column J). When the tanks are replenished it isn't always to capacity, each hold 8000 gallons. Tank 1 will be filled and the remainder will go into Tank 2, but once operations begin it draws from Tank 2 again until depleted. We run in two shifts, the amount used would be entered at the end of every shift in column D and we'd like tank columns to update (column K & J). Here's what we are looking at.
Thank you!

Tank.PNG
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the forum

What exactly are you trying to do ? What do you want to achieve ?
- I have read your post 3 times and cannot see a request or a question :unsure:
 
Upvote 0
I need a VBA code to calculate the amount of CCB used per shift(which would be one entry per shift) entered into column D(starting at D10), this would deduct from Tank 2 (column K10) which begins with 8000. Once Tank 2 is 0, then any entry into column D would deduct from Tank 1 (column J10). If during a shift the tanks are replenished that amount would go into column H and therefore, added to Tank 1 and Tank 2. After replenishment, the amount entered into CCB (column D) would deduct from Tank 2 again, then start the cycle again. The end goal would be to track how much CCB is being used in a shift as well as give the following shift a visual of how much is left in the tanks.
I hope that makes sense.
 
Upvote 0
Perhaps you could provide some sample data and expected results using add-in XL2BB so that anyone trying to help understands what you want
Click on XL2BB icon above post window and read all the notes in that link (there are issues that you should be aware of)
The button to download the app is in the top right corner of the linked page
 
Upvote 0
I need a VBA code to calculate the amount of CCB used per shift(which would be one entry per shift) entered into column D(starting at D10), this would deduct from Tank 2 (column K10) which begins with 8000. Once Tank 2 is 0, then any entry into column D would deduct from Tank 1 (column J10). If during a shift the tanks are replenished that amount would go into column H and therefore, added to Tank 1 and Tank 2. After replenishment, the amount entered into CCB (column D) would deduct from Tank 2 again, then start the cycle again. The end goal would be to track how much CCB is being used in a shift as well as give the following shift a visual of how much is left in the tanks.
I hope that makes sense.

Book1
ABCDEFGHIJK
1Material application
2
3Totals
4Gallons of CCBSandSno meltSaltCCB Replenishment
500000Total Cost
6Costs (Approximate)$0.00$0.00$0.00$0.00$0.00
7
8DateTruckOperatorCCBSandSno MeltSaltCCB ReplenishmentCCB AvailableTank 1Tank 2
916,00080008000
10 
11 
12 
Working Copy
Cell Formulas
RangeFormula
D5, H5D5=SUM(D10:D85)
E5:G5E5=SUM(E9:E85)
D6D6=D5*2.18
E6E6=E5*25
F6F6=F5*15
G6G6=G5*100
I6I6=D6+E6+F6+G6
J9J9=IF(I9>8000,8000)
I10:I12I10=IF(D10>0,(I9-D10),"")
Named Ranges
NameRefers ToCells
'Working Copy'!_FilterDatabase='Working Copy'!$A$8:$G$50D5:G5, I10:I12
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I9:I150Cell Value<=6000textNO
I9:I150Cell Value<=11000textNO
 
Upvote 0
If I understand correctly, you might be able to use formulas. Consider:

Book1
ABCDEFGHIJK
1Material application
2
3Totals
4Gallons of CCBSandSno meltSaltCCB Replenishment
52420000014000Total Cost
6Costs (Approximate)5275600052756
7
8DateTruckOperatorCCBSandSno MeltSaltCCB ReplenishmentCCB AvailableTank 1Tank 2
916,00080008000
1020001400080006000
1135001050080002500
124000650065000
132200430043000
1490001330080005300
1518001150080003500
169000250025000
175000750075000
181700580058000
Sheet2
Cell Formulas
RangeFormula
D5, H5D5=SUM(D10:D85)
E5:G5E5=SUM(E9:E85)
D6D6=D5*2.18
E6E6=E5*25
F6F6=F5*15
G6G6=G5*100
I6I6=D6+E6+F6+G6
J9J9=IF(I9>8000,8000)
I10:I18I10=IF(D10>0,(I9-D10),I9+H10)
J10:J18J10=IF(D10>0,J9-MAX(0,D10-K9),IF(H10>0,MIN(J9+H10,8000),J9))
K10:K18K10=IF(D10>0,MAX(0,K9-D10),IF(H10>0,K9+H10-(J10-J9),K9))


Put the J10 and K10 formulas in and copy down. As you enter number in columns D and H, the totals will adapt as I believe you want. I tweaked the I10 formula too.
 
Upvote 0
Thanks, Eric. Apparently, I was making it much harder than it was. It seems to work. Thanks!
 
Upvote 0
After testing this out this morning, I have two questions: (1) How can I modify the formula to add column H to the calculation if data is entered into column D? (2) How can I have "0" display in columns J & K until data is entered into the rows?
 
Upvote 0
In thinking over your questions, I believe we can use a simpler set of formulas. Try:

Book1
ABCDEFGHIJK
1Material application
2
3Totals
4Gallons of CCBSandSno meltSaltCCB Replenishment
52420000014000Total Cost
6Costs (Approximate)5275600052756
7
8DateTruckOperatorCCBSandSno MeltSaltCCB ReplenishmentCCB AvailableTank 1Tank 2
916,00080008000
10200014,0008,0006,000
11350010,5008,0002,500
1240006,5006,5000
1322004,3004,3000
14900013,3008,0005,300
15180011,5008,0003,500
1690002,5002,5000
1750007,5007,5000
1817005,8005,8000
Sheet2
Cell Formulas
RangeFormula
D5, H5D5=SUM(D10:D85)
E5:G5E5=SUM(E9:E85)
D6D6=D5*2.18
E6E6=E5*25
F6F6=F5*15
G6G6=G5*100
I6I6=D6+E6+F6+G6
J9J9=IF(I9>8000,8000)
I10:I18I10=I9-D10+H10
J10:J18J10=IF(OR(D10>0,H10>0),MIN(I10,8000),0)
K10:K18K10=IF(OR(D10>0,H10>0),I10-J10,0)


Check the I10, J10, and K10 formulas. These also handle your latest requests.
 
Upvote 0

Forum statistics

Threads
1,215,751
Messages
6,126,671
Members
449,326
Latest member
asp123

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