Auto-Population in Excel

cassiekillen

New Member
Joined
Jul 22, 2008
Messages
7
I really need help! I have two spreadsheets in Excel. Say I want to automatically subtract a number I have put into one spreadsheet from a column in the other. Like inventory for instance, one spreadsheet will be a "pick ticket" where people enter how many items they have taken and then it will automatically subtract from the "master inventory spreadsheet"'s inventory column so it automatically updates. Does this make sense? And is it possible?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It kinda makes sense and I think is certainly possible.

Maybe you could give some sample data. Input and expected output.
 
Upvote 0
Okay, I'm going to use a really ridiculous example but bear with me. :)
So say we have 25 bananas.
One spreadsheet will have a column for the date the person took some bananas, a column for their name, and a column for how many bananas were taken.
Then on the other spreadsheet there will be multiple columns such as cost of bananas, types of bananas and overall banana inventory.
What I would like to happen is whenever someone enters a number into the column of how many bananas were taken of the first spreadsheet that that number would automatically subtract itself from the second spreadsheet's overall inventory column.
So someone took five bananas then it would automatically change to 20 in the overall inventory column of the other spreadsheet.
Better?
 
Upvote 0
Yeah, that helps.

My first reaction is to do this:
Have spreadsheet one look like this-

A
1 cost type orig inv current inv
$0.10 yellow 25 =C2-SUM(sheet2!C:C)

The first 3 cols would be values and the 4th would subtract the bananas on the second sheet from your original number.

And that second sheet would something akin to:
A
1 Date name quantity
7/22/2008 Bonzo 5


We will probably have to take the formula a tad deeper b/c I bet you have more than one type of banana or else you have more fruits than just bananas. We can do this with a SUMIF, though. But how's it look so far?

And btw, I LOVE ridiculous examples; so, no problem. Often easier to understand that somebody that gives you samples very specific to their job/company anyway. :)
 
Upvote 0
Welcome to the Board!

You can do what you want with a change event.

Assuming that the number is entered in C2 on sheet1 and removed from C2 on sheet 2, see how this is for a start:

<font face=Tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)<br>    <SPAN style="color:#007F00">'   Code goes in the Worksheet specific module</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range, BananaInventory<br>        <SPAN style="color:#007F00">'   Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")</SPAN><br>        <SPAN style="color:#007F00">'   This is where the bananas are removed</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> rng = Target.Parent.Range("C2")<br>        <SPAN style="color:#007F00">'   This is where you have the total # of Bananas</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> BananaInventory = Sheets("Sheet2").Range("C2")<br>             <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Only look at that range</SPAN><br>            <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#007F00">'   Action if Condition(s) are met (Do your thing here...)</SPAN><br>            <SPAN style="color:#007F00">'   Remove the bananas entered on sheet 1 from the total</SPAN><br>            BananaInventory.Value = BananaInventory.Value - Target.Value<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Note that this is a very basic example and doesn't account for other items or negative values entered (but you can build models as complex as you want).

To give this a shot (on a test workbook), right-click the sheet tab, select View Code, and paste the above into the new window that opens on the right. You can then hit ALT+Q to exit back to Excel and give it a shot.

Hope that helps,
 
Upvote 0
Thank you so much! This is starting to make sense. I am going to test it out and if I have questions I will most likely come back and ask! :)
 
Upvote 0
We'll be here. ;)

Note that I just noticed something missing. It's nothing huge, but the "Dim" line should read:

Dim rng As Range, BananaInventory As Range
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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