(Excel 2013) Combining two cell value without exceeding certain characters limit - excel

I've tried to solve this with excel formula but it is too complicated as I need the workbook to be as less clustered with formulas. So I turned to VBA for aid. So far all the VBA that I've found was mainly for trimming single cell characters only.
What I need for my project is as follows:
A1-Name
B1-Colour
C1-Name(Colour)
If LEN(C1) is less than 81 then nothing is trim. Else, TRIM A1 only without changing B1 so the end result is LEN(C1) is always less than 81.
Thanks.
Edit:
Excel Screenshot 1
What I've tried is:
-I will do "len" on B2 in cell AA2 then another "len" on C2 in cell AB2.
-Then I combine B2 and C2 in cell D2.
-Do another "len" for cell D2 in cell E2.
-If the value in E2 exceed 80, then I've to do "right" for cell B2 in another cell.The value that will be deducted from cell B2 is AA2-80+AB2.
-Once it is done, the new trim B2 will be recombine with C2 in another cell.
That is too many new cells. As you can see, I've to hide some cells that make up what is inside cell F2. So here I am. Beaming up that spotlight with that letter "E" so that Excelman will come to the rescue.

A very simple Excel formula which should do what you want is
=LEFT(A1,MAX(0,78-LEN(B1))) & "(" & B1 & ")"
i.e. take as many characters as possible from A1 so that, when concatenated to "("&B1&")", the total won't exceed 80 characters, and then concatenate that to the "("&B1&")".
Note: Cell references in the formula above are based on your original question. Based on the screenshot, and the edits to your question, the formula would be:
=LEFT(B2,MAX(0,78-LEN(C2))) & "(" & C2 & ")"
If you definitely need VBA, you can use the same functions (i.e. Left and Len) and the same operators (i.e. - and &) in VBA as are used in Excel. The only problem is MAX, which will need to be replaced with Application.Max or with an If statement.

Related

How to auto fill periodic content in Excel that is not counting up like the rows

Let’s assume I have eight excel cells (A1:A8) with the following content:
=MID(B1,1,2)
=MID(B1,3,2)
=MID(B1,5,2)
=MID(B1,7,2)
=MID(B1,9,2)
=MID(B1,11,2)
=MID(B1,13,2)
=MID(B1,15,2)
Now I mark it and drag it down to the next eight cells. I would like to get the same eight formulas just with B2 instead of B1, but excel is giving me B9 for all cells because 9 is the row number of the first new cell.
How can I tell excel that I want to have B2 in the auto fill (and B3 for the next eight and so on)? It is to much data in order to write it all by hand.
Thank you
Put this in A1 and copy down:
=MID(INDEX(B:B,INT((ROW($ZZ1)-1)/8)+1),MOD(ROW($ZZ1)-1,8)*2+1,2)
It will adjust to the next value in column B every 8 rows and will do the 1,3,5,7,...,15 in the start of the MID. No need for any other formula.
Or, since you stated you have Office 365 put this in A1 and it will spill the results:
=MID(INDEX(B:B,INT(SEQUENCE(COUNTA(B:B)*8,,0)/8)+1),MOD(SEQUENCE(COUNTA(B:B)*8,,0),8)*2+1,2)
If you want to keep your original formula, this will involve 4 steps:
Place the following formula in cell A1
="=MID(" & "B" & ROUNDUP(ROW(B1)/8, 0) & ", " & MOD(ROW(B1)-1,8) * 2 + 1 & ", 2)"
Copy down as far as needed.
Select whole of column A, Copy, Paste Special > Values
Select whole of Column A, Ctrl+H (Replace), Find what "=", Replace with "=", Replace All.
This will create formulas in Column A is in your question.

How to calculate conditional cell formula, with adjacent cell formula dependent on 1st cell's calculated, not printed value?

I am trying to figure an Excel formula and Google is not helping.
I almost have what I am trying to do, but need a 'dummy' column where I do the math in the column cells.
What this means:
1) What I have working:
Cell A1, with math formula (I wish to delete this 'dummy' cell and incorporate this into the formula in Cell B1, see further explanation below)
=SUM((6.75*1)+(5.73*2)+3)
Cell B1, with value from Cell A1 but limited to an integer less than or equal to 80
=IF(SUM(A1)>80, 80, SUM(A1))
Cell C1, with a value looking at Cell B1 and entering in this cell either 0 or any integer greater than 80
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: This works perfectly, I change any values in the Cell A1 formula and it correctly reflects in Cells B1 & C1.
2) The missing piece:
I would like to combine the two formulas above in cells A1 & B1 into one cell, and still have the same results described above for each of the cells.
To articulate this another way is:
have a cell with a math formula,
calculate the results of that formula, and then,
enter back in the same cell that formulas results,
with the condition of 'less than or equal to 80'
while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of the first cell.
As an example:
Using only Cells A1 and B1 in a spreadsheet, and combining the above working formulas (which do not work for me in Excel), it would look like this:
Cell A1:
=IF(SUM((6.75*10)+(5.73*7)+8.5)>80, 80, SUM(B21))
Note: Cell A1 formula from above, =SUM((6.75*1)+(5.73*2)+3), combined with Cell B1 formula from above, =IF(SUM(A1)>80, 80, SUM(A1)) (with the Cell A1 formula replacing both 'A1' values in the Cell B1 formula).
Cell B1:
=IF(SUM(A1)>80,SUM(A1)-80,"0")
Note: Identical to the Cell C1 formula above.
Is it possible to do this, calculate the results of a cell's formula, while a formula in an adjacent cell is dependent on the calculated, but un-printed, value of that first cell?
I realize writing this out, it's more complicated than I originally anticipated, which explains why Google wasn't getting me anywhere.
Thanks for any hints.
Phil
Strictly speaking, this is not possible. A cell has only 1 value and that is the result of all calculations. The IF statement is not hiding the value of the cell. It is changing the value.
A formula to another cell can only use the final value of the cell. It can't extract part of the formula in the other cell. There's no way for Excel to know which part to extract, even if there's only a single calculation in an IF statement.
That said, there is a different workaround possible in your case... and that is to change how your value is displayed through custom formatting. Formulas change the value of cells, whereas formatting changes how those values are displayed.
Place your formula in cell A1: =6.75*10+5.73*7+3
Right click on cell A1 and select Format Cells...
Make sure you're on the Number Tab
In the Category column, select Custom
Enter this formula in the Type box: [>80]"80";[<=80]General
Enter this formula in B1:=IF(A1>80,A1-80,0)
Check that the number format of B1 is still "General" or "Number"
The result is A1 has calculated and stored the actual value, but displays the text string "80" if it's value is above 80. You can then use the actual value from A1 in other formulas.
NOTE: This type of custom formatting is extremely poor practice as it can become very confusing and very error prone. The value of the cell is different to what it is showing and if other users are unaware, creating new formulas referring to the affected cell can unwittingly produce incorrect and/or unexpected results.
In particular, Excel tries to be helpful and can automatically copy the formatting from one cell to another if it is next to the original cell or if it refers to only the original cell in a basic formula. Copying and pasting also copies the formatting by default. Unintentionally copying the formatting to other cells will also alter how they appear.
Also note that you don't need to put SUM() around a formula that already had the addition operators included; and Excel uses order of operations so you don't need the brackets to do multiplication before addition.
Lastly, you could also just use =MAX(A1-80,0) in B1.

Sum by row with reference to other cell values

I have a vague memory doing this a year back and want to repeat the function. I want to use B2 as a reference to my formula, where my formula is reading in values from another tab and can be expanded by dragging and dropping. My picture is trying to illustrate the issue,
The pink cells are not using the reference cell B2, heading Formula 1 show the formula in column B.
The blue cells is what I have now, column D is the results from the formula in column E (row by row). Here I have created the formula in cell D4 and then dragged it down to D6.
The green cell is what I want to achieve, note the discrepancy marked in red.
I want to be able to write the formula in cell D4 and then drag it down to D6. How can this be done without adding new columns.
Use this:
=INDIRECT("'" & $B$2 & "'!C" & ROW())
I added '' around the sheet name in case the sheet name in B2 contains spaces.

How to randomly select cell and the adjacent cell on excel

I am trying to find a formula on excel that will allow me to randomly select a cell between a range (this part I have found a formula for) and have the value pasted into another cell AND then have the cell next to the randomly selected cell's value also selected and pasted into a different cell.
Not sure if this makes sense so I will explain what I'm trying to do.
I have a column full of years and the adjacent column full of prices that correspond to each year. I want a year randomly selected and pasted into a cell lower down on the spreadsheet, and I want the corresponding price for this randomly selected year pasted next to this cell.
Thank you in advance!
Anna
Say the data is in A1 through B10
In D1 enter:
=INDEX(A1:A10,RANDBETWEEN(1,10))
and in E1 enter:
=VLOOKUP(D1,A1:B10,2,FALSE)
Another approach is to enter:
=RANDBETWEEN(1,10)
=INDIRECT("A" & C1)
=INDIRECT("B" & C1)
In C1 through E1
(Either approach will work if column A contains years rather than names)
Yet another approach is to enter:
=RANDBETWEEN(1,10)
=INDEX(A1:A10,C1)
=INDEX(B1:B10,C1)
In C1 through E1

Excel - Drag and repeat formula pattern series

I am trying to replicate a pattern of formulas in excel but it's not appearing the way I expect but I'm looking for a solution.
I have the first 2 rows in a table defined and it has 4 columns
The formulas are as follows:
A1 =CONCATENATE(Scores!D11," (",Scores!F11,")")
B1 =Scores!AF11
C1 =Scores!AH11
D1 =Scores!AH15
A2 =CONCATENATE(Scores!D17," (",Scores!F17,")")
B2 =Scores!AF17
C2 =Scores!AH17
D2 =Scores!AH21
I expected when I highlight the cells and dragged down that it would repeat the formula by adding 6 to all the value as shown above.
Is there an easy way to autofill the rows I need as I have to populate over 80 and possible more in the future.
If you use instead in A1:
=CONCATENATE(INDEX(Scores!D:D,11+6*(ROWS($1:1)-1))," (",INDEX(Scores!F:F,11+6*(ROWS($1:1)-1)),")")
then copy down as required, which has the additional benefit of avoiding volatile INDIRECT set-ups.
Regards
You could use Indirect() for the formulas to determine which row they are supposed to go after. Basing the logic off of the current row on which the formula resides:
In A1:
=Concatenate(Indirect("Scores!D" & (11 + (Row()-1)*6)), " (", Indirect("Scores!F" & (11 + (Row()-1)*6)), ")")
In B1:
=Indirect("Scores!AF" & (11 + (Row()-1)*6))
You can see what's happening more clearly in that B1 example. We are dynamically determining the number 11 by using that formula 11 + (Row()-1)*6. For B1 the ROW() returns 0, so the formula is 11+(0-1)*6 or 11. That 11 is concatenated with Scores!AF and then Indirect() returns that back to the formula so it can then look up Scores!AF11 from the workbook and return it's value.
When you copy that formula down to B2 the ROW() returns 2 and the formula then works out to 17, which is your B1 value + 6.
That's a few hops, skips, and jumps to get what you need, but the formula will copy down nicely and save you a lot of typing.

Resources