Is there a way to put a variable in a custom format?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,525
Office Version
  1. 365
Platform
  1. Windows
Is there any way that I can put a variable in a custom format?

In this table, I would like to be able to calculate in H5, highlighted in yellow, the value in G5, next to it. I can't do that because of the way I generated the results in the rest of Column H, resulting in a non-numeric value. But if I could put the "/ 7" in the custom format, where the "7" is a variable, then the value would remain numeric.

Book1
BCDEFGH
5-3=0-3-11%+3+3???
6EventsHitsMissesTries%Rank %Rank %
7742667%44 / 7
8672978%11 / 7
9542667%44 / 7
10453863%66 / 7
11352771%22 / 7
12242667%44 / 7
13134743%77 / 7
140
Sheet1
Cell Formulas
RangeFormula
C5:G5C5=OFFSET(C6,1,0)-OFFSET(C6,2,0)
E7:E13E7=C7+D7
F7:F13F7=C7/E7
G7:G13G7=RANK.AVG(F7,OFFSET(F$6,1,0):OFFSET(F$14,-1,0),0)
H7:H13H7=RANK.AVG(F7,OFFSET(F$6,1,0):OFFSET(F$14,-1,0),0) & " / " & OFFSET($B$6,1,0)
B7:B13B7=OFFSET(B7,1,0)+1

Thanks
 
What about This formula for H5:
Excel Formula:
=(LEFT(OFFSET(H6,1,0),FIND("/",OFFSET(H6,1,0))-1)-LEFT(OFFSET(H6,2,0),FIND("/",OFFSET(H6,2,0))-1))/OFFSET($B$6,1,0)

Or
Excel Formula:
=(LEFT(OFFSET(H6,1,0),FIND("/",OFFSET(H6,1,0))-1)-LEFT(OFFSET(H6,2,0),FIND("/",OFFSET(H6,2,0))-1))
Wow!!! If they are doing what I think they are, it should work. Thanks
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I am asking if there is a way to put the value of a cell or variable in a custom format expression.
I think we can do what you want using event code. If I am right, you would only need one Rank column (G) which would have the calculated rank value (a number) with a Custom Format given to it by the event code so it would look like the "division" you show.. If you want to pursue this, I would need to know the following...

1) Are the values in Column B manually entered? If not, what is the formula in cell B5?

2) What is the formula in cell G5?

3) Just checking... all your examples show the division by what is in cell B5 but your really want the divisor for each row to come from the value in Column B on that same row, correct?
 
Upvote 0
I think we can do what you want using event code. If I am right, you would only need one Rank column (G) which would have the calculated rank value (a number) with a Custom Format given to it by the event code so it would look like the "division" you show.. If you want to pursue this, I would need to know the following...

1) Are the values in Column B manually entered? If not, what is the formula in cell B5?
They are generated by adding "1" to the cell immediately below. I think this is shown in the last row of the xl2bb cell formulas in post #7 above.
VBA Code:
=OFFSET(B7,1,0)+1

2) What is the formula in cell G5?
This is also in thexl2bb table above. The 3 header cells (C5:G5) all have the same formula:
Code:
=OFFSET(C6,1,0)-OFFSET(C6,2,0)

3) Just checking... all your examples show the division by what is in cell B5 but your really want the divisor for each row to come from the value in Column B on that same row, correct?
I think you meant B7? B5 has literal text "Changes→".

I want all the "divisors" to use the number in B7. This is shown in the second part of the formula in H7:H13:
Code:
 & " / " & OFFSET($B$6,1,0)

These are display divisors, not actual arithmetic divisors. I could have set the display to "4 of 7" instead of "4 / 7".
 
Upvote 0
Right-click the tab on the worksheet containing your data, select View Code from the popup menu that appears and copy/paste the following code into the code window that appears...
VBA Code:
Private Sub Worksheet_Calculate()
  Dim R As Long
  For R = 7 To Cells(Rows.Count, "G").End(xlUp).Row
    Cells(R, "G").NumberFormat = "0 "" / """ & Range("B7").Value
  Next
End Sub
Now, when ever the worksheet is recalculated or a cell's value is changed on the worksheet, the ranks in Column G will become formatted in the way you want but the cell values will still be numbers.
 
Upvote 0
Right-click the tab on the worksheet containing your data, select View Code from the popup menu that appears and copy/paste the following code into the code window that appears...
VBA Code:
Private Sub Worksheet_Calculate()
  Dim R As Long
  For R = 7 To Cells(Rows.Count, "G").End(xlUp).Row
    Cells(R, "G").NumberFormat = "0 "" / """ & Range("B7").Value
  Next
End Sub
Now, when ever the worksheet is recalculated or a cell's value is changed on the worksheet, the ranks in Column G will become formatted in the way you want but the cell values will still be numbers.
It's a little past my bedtime, so my eyes are a bit droopy. I'll take this up first thing in the morning. This may open the door to a whole range of new possibilities.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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