Change part of excel formula with a constant value - excel

I have an excel formula across a column for which the base changes every "x" number of rows. Note this "x" is not constant and keeps changing. e.g.
=D1/SUM(D$1:D$4)
=D2/SUM(D$1:D$4)
=D3/SUM(D$1:D$4)
=D4/SUM(D$1:D$4)
=D5/SUM(D$5:D$9)
=D6/SUM(D$5:D$9)
=D7/SUM(D$5:D$9)
=D8/SUM(D$5:D$9)
=D9/SUM(D$5:D$9)
I am trying to change the first part of the formulas without changing the second and vice versa. e.g. changing the numerator by 10 cells.
=D11/SUM(D$1:D$4)
=D12/SUM(D$1:D$4)
=D13/SUM(D$1:D$4)
=D14/SUM(D$1:D$4)
=D15/SUM(D$5:D$9)
=D16/SUM(D$5:D$9)
=D17/SUM(D$5:D$9)
=D18/SUM(D$5:D$9)
=D19/SUM(D$5:D$9)
or, changing the base by 100. e.g.
=D1/SUM(D$100:D$104)
=D2/SUM(D$100:D$104)
=D3/SUM(D$100:D$104)
=D4/SUM(D$100:D$104)
=D5/SUM(D$105:D$109)
=D6/SUM(D$105:D$109)
=D7/SUM(D$105:D$109)
=D8/SUM(D$105:D$109)
=D9/SUM(D$105:D$109)
Sometimes, both. Any guidance on how this can be possible?
Thank you.

the first part of this problem seems easy unless I am missing something?
Part 1:
Since the denominator is already in $x form, you can select and COPY the whole range of formulas and PASTE them 10 rows down and then CUT and paste it back into position. The COPY will update the numerators appropriately and when you CUT and PASTE it back into position they will now be just as you want? The second question will be a bit more of a challenge!
Part 2:
OK without VBA I can only think of a really long-winded way to change your demoninators, but I just checked that it does work:
To change the bottom.
Search and replace = with '=
Now you can edit the formulas more freely.
Search and replace D with D%
Search and replace D%$ with D
Search and replace D% with D$
get rid of the '= by using the Data>text to columns option
Now use the copy and paste, cut paste trick from part 1.
Then if you still need your $s back as they were you essentially repeat 1 to 5 again.
Sorry, this looks really long-winded, but if you are desperate and back up before you start it should work.

An excel formula can't replace another cells excel formula... One approach is to make the formula into text and then transform it by other formulas. When transformation is done, you could paste the formula back.
So for changing the D1 -> D11, I would build a dummy series (column K) then write a formula (cell L1). Then I can copy the formula and paste it into the correct column.
Replaceing the "=", with a special character and then you can transform the formulas.
(Column F).
In Column I, the formula used is: =RIGHT(F1,LEN(F1)-FIND("/",F1))
For changing D$1 -> D$100, I think I just would copy and replace it by searching in "Formulas".
This approach can be feasible for acouple of hundred cells. If the list is very long, I would recommend some VBA solution, where you can grab a cells formula with .Range("A1").Formula

Related

Excel - How to fix letter

I have a column B with numbers and I want my row 2 to be 1-B3, 1-B4, 1-B5 and so forth.
If I type in =1-B3 and extend it to the right it becomes 1-C3, 1-D3 and so forth.
If I type in =1=$B3 and extend it to the right it just stays 1-B3.
How do I lock the letter B so that only the number will increase when I extent it to the right?
Yeah. So you can't do that in a single, manual copy or range extension.
You could (as JvdV suggested) write a more complex formula, that will transpose on copy/extend. But I'm not sure if that's what you're trying to learn.
You could also write vb to automate the construction your formula. Again though, I'm pretty sure that's also not what you're asking.
Assuming you're just looking for a simple manual solution to what you're trying to do:
Enter the formula =1=$B3 in a cell in any EMPTY column
Doesn't matter where that cell is
Copy/extend that cell down the COLUMN to match all your column B values
Select the entire suite and Copy
Select the target starting cell, in your target row
Right Click >> Paste Special
Select Paste Formulas and Check Transpose >> Click Ok
You can now of course delete the 'temporary' column of formula

How to transpose Columns to rows (with interruptions) in Excel?

Suppose that we have two columns including a million rows
like this:
What is the right formula or VBA to make another arranged table like this?
For a pure Excel solution try this.
First you need to add a helper column. This just returns TRUE on a header row or FALSE otherwise. This isn't strictly necessary, but it will make the rest of the formulas a little simpler. In the sample you provided above, type this into cell C1:
=IF(A1=B1,TRUE,FALSE)
Now enter this is cell D1:
=IF(AND(C1,NOT(C2)),A2,"")
What this does is check if the current row is a header but not the next, and copies the first cell of the next row if it is, or returns a blank string if it isn't.
Each subsequent cell follows the same pattern, but it first checks if the previous cell is blank. Enter this function into cell E1:
=IF(D1="","",IF(AND(C1,NOT(C3)),A3,""))
Now you just need to copy this pattern outfor another 10 cells. Unfortunately copy-and-paste won't work as you need to increment A3 and C3 downwards, while copy-and-paste with increment them to the right. So, from E1, we get:
F1: =IF(E1="","",IF(AND(C1,NOT(C4)),A4,""))
G1: =IF(F1="","",IF(AND(C1,NOT(C5)),A5,""))
.
.
.
O1: =IF(N1="","",IF(AND(C1,NOT(C13)),A13,""))
Now copy those cells to the bottom of the data set and you should get the results you're after. Here's an example:
Note the extra TRUE in cell C21 so that the last calculation terminates correctly.
However, if you really have a million rows in your data set, I would question the wisdom of using Excel at all. Depending on your circumstances and resources, you may be better off keeping the data in a text file and processing it with a proper scripting language.
Problem Solved in excelforum by JohnTopley here:
http://www.excelforum.com/excel-formulas-and-functions/1174447-interrupted-transpose.html

Concatenate repeats first row cell values even though formula selects different cells

I am trying to prep some zip codes to go into the WHERE clause of a SQL query:
WHERE [Zip_code] IN ()
To do this I put all the values into Excel and want to concatenate the zip codes with an apostrophe at the beginning and an apostrophe, a comma, and a space at the end so 99508 would become '99508', . So I wrote the equation
=Concatenate("'",D2,"', ") where D2 is the zipcode. It worked for the top row producing '99058', but when I filled down it still showed the value for D2
To make matters more confusing, when I click on the cells and see the formulas, they are tracking the proper cells but still show data for the top row
I have tried everything that I can think of to solve the problem: reformatting everything as text, formatting the zipcodes as Numbers rather than text, putting the text in the adjoining columns (C2 has an apostrophe, D2 has the Zip code, E2 has apostrophe, comma, and space) and concatenating, using & instead of concatenate ("'"&D2&"', " ), concatenating A on the front and B on the end to do a find and replace, but I still get the same result. If I select a concatenated cell, click on the formula bar, and press enter the cell shows the proper concatenation, but I would rather not do that for every single cell.
My co-worker suggests including that the zip codes were taken from pivot table outputs.
Any suggestions?
Turns out that calculations had somehow been set to manual instead of automatic.
Switching back to automatic solved the problem.
use this instead
=concatenate("'";D2;"',")
idk if gonna work on you sheet, bc i have in spanish my MS-office suite
but if doesn't work, replace the ; for ,
if you copy the formula to the other cells, this must change to the next row
First is clear the worksheet format
secondly, click on file on the excel, then to option, to formula after formula, check the position of the calculation. if its in automatic change it back to Manual and then change it back to automatic. That will solve it.

Any way to copy/paste formulas in a range of cells but keep absolute?

I have a matrix of data and each cell is a formula. All cell formulas are relative, so when I copy and paste just below, the formulas are now off.
Here's what I know works:
Change each cell's formula from relative to absolute
Copy the text from each formula, then paste this text below
I don't want to go and F4 each part of every formula for dozens of cells. Is there a way to copy paste a large batch but tell Excel to keep the exact formulas as written?
I personally do a bulk Find and Replace on the original range, replacing all "=" signs with a random text string which is guaranteed to not occur anywhere within those formulas, my usual choice being "##".
This converts all the formulas to text strings, after which you can paste the range before then performing the reverse Find and Replace, i.e. replacing "##" with "=", which coerces Excel into treating the strings as actual formulas once more.
Of course, if we're talking about a very large amount of formulas, i.e. several thousand, then this operation can take a while to perform, since not only is Excel required to carry out the Find and Replace on all strings, but also to calculate all the newly-created formulas.
Regards
When pasting, right click and choose "Paste Special" and use "Paste Formulas" (the fx icon).
Edit: Ah, I realize now this only works for 'fully anchored' ($A$1) cell references.

Change variable horizontally in excel formula

I want to change a variable in an excel formula horizontally and maintain one variable constant.
O3/$C18, P3/$C18, Q3/$C18
I can keep the the bottom variable constant by using the $ symbol but when I want to extend the formula to additional cells, the top variable does not change horizontally, rather vertically.
Thank you for your help. Cheers
The dollar signs in excel "fix" the item to their right
$C18
means C will always be fixed, and 18 can change
C$18 means C can change, but 18 is always fixed.
$C$18 means C is fixed and 18 is fixed (ie always use C18 no matter what direction you drag the cell)
I dont fully understand what you want to do but hopefully the above will help
based on the comments below i think i understand what you mean
try a formula like this
=INDIRECT(ADDRESS(1,ROW()))/$C$18
here address takes the row and column, so row = 1 and column = which ever row you are on (so row1 = A, row2=B etc)
then indirect lets you use that as a reference point
Hope that works
If I understand you correctly, you want to copy your formula vertically, but have the columns update as if you were copying horizontally. For example, you want to copy =O3 to the cell below it as =P3.
For the top, consider the Offset() and Row() functions. Let's say that Cells A1,B1,C1 are 1,2, and 3. Try =OFFSET($A$1,0,ROW()-1). If you copy that formula vertically, the result will be 1, then 2, then 3.
So in your case, try =OFFSET($O$3,0,ROW()-1). It probably needs a little adjustment.
Here's another way to do this:
Start with the formula in this form:
=O$3/$P$18
Copy and paste it across so that you get:
=O$3/$P$18 =P$3/$P$18 =Q$3/$P$18
Copy the two formulas you pasted and select the cell below the first formula.
Then do a Paste Special / Transpose, which can be accessed by right-clicking the selected cell (that is, the one below the first formula that you entered) and then choosing the button that shows a little two-cell range flat and then upright.
Finish up by deleting the formulas in the cells you just copied from.

Resources