Need Excel help
Need Excel help
Could one of the excel gurus on the site give me a hand with a formula?
the sheet looks like this:
Title 1 12.0%
Title 2 31.0%
Title 3 24.0%
Title 4 5.0%
Title 5 6.0%
Title 6 7.0%
Title 7 7.0%
Title 8 8.0%
100.0%
What I need is all the % values to be able to be changed by the user, and have the others adjust to equal 100%.So if I changed say title 2 to 5%, the other values will auto adjust to distribute the difference and equal 100%. A few of us have been stumped by this, I'm hoping someone can solve it, if it's possible.
the sheet looks like this:
Title 1 12.0%
Title 2 31.0%
Title 3 24.0%
Title 4 5.0%
Title 5 6.0%
Title 6 7.0%
Title 7 7.0%
Title 8 8.0%
100.0%
What I need is all the % values to be able to be changed by the user, and have the others adjust to equal 100%.So if I changed say title 2 to 5%, the other values will auto adjust to distribute the difference and equal 100%. A few of us have been stumped by this, I'm hoping someone can solve it, if it's possible.
Here's a typical-for-me overdone VBA solution. I'm not sure you can do what you want with an Excel function, because you would need to track both a value and a have a function in a cell, which a cell can only have one or the other.
So, open up the VBA editor (Alt-F11), open up Sheet1 or whatever your sheet is called, and paste this in.
You will need to update the number or rows you are summing to be 100% (1) in the code. Once you have reached 100, every cell you change will affect all the others. There may be times when you want to start over with new starting values. In that case, set every cell to zero and start over. The rebalancing won't happen until you hit 100%.
One annoyance is that you will have to arrow out of your cells twice. It's a side effect of the Undo command I use to get the old value of the cell. Hopefully you can live with it.
Hope this helps.
So, open up the VBA editor (Alt-F11), open up Sheet1 or whatever your sheet is called, and paste this in.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Dim oldValue As Double
Dim newValue As Double
Dim oldSum As Double
Dim delta As Double
Dim maxRows As Integer
' Set this to the number of rows you are summing to 100%
maxRows = 8
If Not IsNumeric(Target.Value) Then Exit Sub
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
' get old Value
newValue = Target.Value
Application.Undo
oldValue = Target.Value
Target.Value = newValue
' Get the sum before the change
For i = 1 To maxRows
If i <> Target.Row Then
oldSum = oldSum + Me.Cells(i, Target.Column)
End If
Next
' Don't start recalulating until we hit 100%
If oldSum + oldValue < 1 Then
Application.EnableEvents = True
Exit Sub
End If
' Figure out how much the other cells need to change by
If oldSum <> 0 Then
delta = (1 - Target.Value) / (1 - (1 - oldSum))
Else
delta = 0
End If
' update all the other cells
For i = 1 To maxRows
If i <> Target.Row Then
Me.Cells(i, Target.Column) = Me.Cells(i, Target.Column) * delta
End If
Next
Application.EnableEvents = True
End Sub
One annoyance is that you will have to arrow out of your cells twice. It's a side effect of the Undo command I use to get the old value of the cell. Hopefully you can live with it.
Hope this helps.
Last edited by Anachostic; Aug 7, 2009 at 08:01 PM. Reason: clarification
Trending Topics
Ok, with the success of my last request, maybe someone can help me again.
I have a massive excel file, and need to automate a proccess because doing it manual could kill me. There's a Master sheet about 100 rows by 160 columns. Each row is a product and each column are product specs. From this master sheet, I need to create a seperate sheet for each of the rows (products). The new sheet is a template and certain cells need to be populated with the info from the Master sheet. I have done a few of these and I just have those cells linked to the respective cell on the master. Is there a way I can create a copy of this template, but have the formula basically go from referencing cell C3 to C4 and so on up to 100. I need a way to make this fast and easy.
I have a massive excel file, and need to automate a proccess because doing it manual could kill me. There's a Master sheet about 100 rows by 160 columns. Each row is a product and each column are product specs. From this master sheet, I need to create a seperate sheet for each of the rows (products). The new sheet is a template and certain cells need to be populated with the info from the Master sheet. I have done a few of these and I just have those cells linked to the respective cell on the master. Is there a way I can create a copy of this template, but have the formula basically go from referencing cell C3 to C4 and so on up to 100. I need a way to make this fast and easy.
is it possible for this to work:
My forumla is =MASTER!H5
instead of having the 5 in H5, could I make that a link to a cell in my sheet where I can change the number. I.E =MASTER!H(B6) and whatever that value is will make it look up that row in my master sheet?
My forumla is =MASTER!H5
instead of having the 5 in H5, could I make that a link to a cell in my sheet where I can change the number. I.E =MASTER!H(B6) and whatever that value is will make it look up that row in my master sheet?
Two ways to approach:
1) Pull the table into Access and make a report.
2) Excel -- write a VBA function to traverse the table and make the detail sheets you want.
I'm not going to do them for you though.
1) Pull the table into Access and make a report.
2) Excel -- write a VBA function to traverse the table and make the detail sheets you want.
I'm not going to do them for you though.
I came up with an interim solution, which was to re-write the formulas in the template to use indirect references, and use a random cell on the template to point those forumlas to the correct row. Basically I took it from having to manually change the formulas in like 3000 cells, to changing a reference point in 100.
I feel retarded looking at what everyone's saying even though I passed the certification test. Oh well.
=INDIRECT(CONCATENATE("MASTER!H",B6))
I was just thinking that this almost seems like a mailmerge process -- except instead of pulling in address info to a template, you're pulling in the product info.
May want to see if maybe the fastest way is to make the template in Word and use MailMerge to pull in the relevant fields from each row in the spreadsheet.
May want to see if maybe the fastest way is to make the template in Word and use MailMerge to pull in the relevant fields from each row in the spreadsheet.
I was just thinking that this almost seems like a mailmerge process -- except instead of pulling in address info to a template, you're pulling in the product info.
May want to see if maybe the fastest way is to make the template in Word and use MailMerge to pull in the relevant fields from each row in the spreadsheet.
May want to see if maybe the fastest way is to make the template in Word and use MailMerge to pull in the relevant fields from each row in the spreadsheet.
new question. If I embed an image on 1 sheet, can I use a link to re-display the image on a subsequent sheet? This is in the interest of keeping the file less than 30mb.
It seems Excel is smart enough to only maintain a single reference to an image within itself and whether you reload the image from disk or copy it internally, it reuses that reference.
Thread
Thread Starter
Forum
Replies
Last Post
08_UA7_Gr33k
Member Cars for Sale
13
Feb 11, 2016 02:17 PM
InFaMouSLink
Car Parts for Sale
6
Oct 27, 2015 06:52 PM
08_UA7_Gr33k
Member Cars for Sale
1
Sep 27, 2015 01:56 PM







Anachostic...
