honkin

Board Regular
Joined
Mar 20, 2012
Messages
145
Office Version
  1. 2016
Platform
  1. MacOS
Hi have researched custom format of cells, but have not been able to find a response which deals with my issue.

Is it possible to have a cell display as 3*3, 4*4, 5*5 and so on? So regardless of what number is typed, it displays as number*number.

Is there as way for this to be done?

Thanks in advance
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
6,791
Hope I understood well,

you can try PowerQuery: Expression.Evaluate

rawEvaluate
5*5
25​
27-4
23​
33/11
3​
11+4.5
15.5​
11*11
121​

or

defined name with VBA function Evaluate , eg. =EVALUATE(Sheet1!$A1) named as Result
then A1: 5*5
and in B1 use =Result
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,333
Office Version
  1. 2010
Platform
  1. Windows
Is it possible to have a cell display as 3*3, 4*4, 5*5 and so on? So regardless of what number is typed, it displays as number*number.
It is not possible to do this with a direct Custom Cell Format; however, we can create a Custom Cell Format in VBA event code that will do what you asked for.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim X As Long, Txt As String, Cell As Range
  If Not Intersect(Columns("[B][COLOR="#FF0000"]C[/COLOR][/B]"), Target) Is Nothing Then
    For Each Cell In Intersect(Columns("[B][COLOR="#FF0000"]C[/COLOR][/B]"), Target)
      Txt = Cell.Value
      For X = 1 To Len(Txt)
        If Mid(Txt, X, 1) Like "#" Then Mid(Txt, X) = "0"
      Next
      Cell.NumberFormat = Txt & "\*" & Cell.Value
    Next
  End If
End Sub
NOTE: You did not tell us what column you would be entering numbers into, so I guessed at Column C. If that is incorrect, change the red highlighted column letters to the correct column reference.

HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 

honkin

Board Regular
Joined
Mar 20, 2012
Messages
145
Office Version
  1. 2016
Platform
  1. MacOS
Thanks so much sandy, but was not trying to do a calculation, just format the number in the cell a particular way. Thanks so much for your reply

Hope I understood well,

you can try PowerQuery: Expression.Evaluate

[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]raw[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Evaluate[/COLOR]
5*5
25​
27-4
23​
33/11
3​
11+4.5
15.5​
11*11
121​

<tbody>
</tbody>


or

defined name with VBA function Evaluate , eg. =EVALUATE(Sheet1!$A1) named as Result
then A1: 5*5
and in B1 use =Result
 

honkin

Board Regular
Joined
Mar 20, 2012
Messages
145
Office Version
  1. 2016
Platform
  1. MacOS
Absolutely nailed in Rick. That works a treat so thank you very much.
It is not possible to do this with a direct Custom Cell Format; however, we can create a Custom Cell Format in VBA event code that will do what you asked for.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim X As Long, Txt As String, Cell As Range
  If Not Intersect(Columns("[B][COLOR=#FF0000]C[/COLOR][/B]"), Target) Is Nothing Then
    For Each Cell In Intersect(Columns("[B][COLOR=#FF0000]C[/COLOR][/B]"), Target)
      Txt = Cell.Value
      For X = 1 To Len(Txt)
        If Mid(Txt, X, 1) Like "#" Then Mid(Txt, X) = "0"
      Next
      Cell.NumberFormat = Txt & "\*" & Cell.Value
    Next
  End If
End Sub
NOTE: You did not tell us what column you would be entering numbers into, so I guessed at Column C. If that is incorrect, change the red highlighted column letters to the correct column reference.

HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Can I assume this area will also work for conditional formatting? I have been racking my brain trying to work out how to do something and you have just given me an idea, but when I tried my code, it isn't how I would like.

I want to colour both a cell and text and bold the text based on what is in the cells. I wrote a formula and it works fine brilliantly. Here is the formula:-

Code:
=AND(TEXT($B2,"dd/mm/yyyy")=TEXT(TODAY(),"dd/mm/yyyy"), OR($A2="FA_Win_3", $A2="FA_Win_2"))
What I did was the select the range A2:A70, to make sure it has always got every row covered. So when the document is opened, if the date in B is today and the text in A is either of those you see, the cell is coloured green, the text white and bold.

The only issue is that other members of the team here in the office input data daily to the sheet and when that happens, the conditional formatting gets all messed up and no longer works on the full range it should. There might be 3 of 4 conditional format rules showing. You see, as each day transpires, old data is removed and new data pasted in. I need a way to protect A2:A70 so it acts regardless. That's why your method seemed perfect.

Here is what I did in VBA, but to no avail, so I have obviously done something wrong in the code. Sorry to ask for further assistance, but it is doing my head in. How does this look to your eye:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    ' This method has a drawback and is that the undo feature in this sheet no longer works (if you can live with it, no problem)
    ' Here is an option to bring it back: [URL]https://www.jkp-ads.com/Articles/UndoWithVBA04.asp[/URL]

    ' Define variables
    Dim targetRange As Range
    Dim formulaEval As String

    ' Define the Range. This is the range that receives the conditional format
    Set targetRange = Range("A2:A70")

    ' Define the formula evaluated by the conditional format (replace ; for ,)
    formulaEval = "=AND(TEXT(" B2 ",""dd/mm/yyyy"")=TEXT(TODAY(),""dd/mm/yyyy""), OR(A" 2 "=""FA_Win_3"", A" 2 "=""FA_Win_2""))"

    If Not Intersect(Target, targetRange) Is Nothing Then
        With Target
            .FormatConditions.Add Type:=xlExpression, Formula1:=formulaEval
            .FormatConditions(.FormatConditions.Count).SetFirstPriority

            ' This is where the format applied is defined (you can record a macro and replace the code here)
            With .FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = RGB(0, 176, 80)
                .TintAndShade = 0
                .Font.Color = RGB(255, 255, 255)
                .Font.Bold = True
            End With
            .FormatConditions(1).StopIfTrue = False
        End With
    End If

End Sub

Thanks so much in advance, Rick
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,109,367
Messages
5,528,271
Members
409,813
Latest member
robyrux

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top