Hi,
I have a situation where i need to count based on format of the cells like "General format" or "Number format"
Is there any formula to count the data based on "General or Number format"?? Attached Excel file for your reference.
You need the Cell function
Try this blog by Mynda
https://www.myonlinetraininghub.com/excel-cell-function
You will need to reference back to the blog as the output are kind of codes, but they will tell you the cell formatting and you can then countif
In my opinion, you'd be better off rethinking your approach. Formatting should reflect data, not be used as data.
Hi Purfleet,
Your link taught me a new things. First of all thanks a lot.
You are right, if i insert new column to get cell format for each cell, then only i can count.
Is there any other option to count directly with single column. If any anyone know the answer, please help me. Attached file for your reference.
I actually do agree with Velouria - you really shouldnt be calculating anything on a cell format.
To my knowledge you cant use ranges with the Cell & Address function, If you have to count formats i would used the formula above with the extra column and then either delete or hide the column after use.
The other possiblity is VBA, the below code would count the Number format and general format, but would need to add more ifs if you want anything else.
Sub cFormat()
Dim r As Range
Dim C As Range
Dim nf As Integer
Dim gf As Integer
nf = 0
gf = 0
Set r = Range("f4:f8")
For Each C In r
Debug.Print C.DisplayFormat.NumberFormat
If C.DisplayFormat.NumberFormat = "#,##0.00" Then
nf = nf + 1
End If
If C.DisplayFormat.NumberFormat = "General" Then
gf = gf + 1
End If
Next C
MsgBox "Number format = " & nf & " General Format = " & gf
End Sub
Hi Rafi
Just wondering why do you want to count based on cell format?
What is the practical use?
Sunny
Hi Sunnykow,
Open the attached file. My requirement is in "column I". This is my Journal entry (Finance term). Each and every day i need to fill the data and upload into SAP tool.
If i have any value in Number format in "Column I" , SAP tool will throw me the run time error. It means that particular SAP T-code will not accept Number format values.
If you check in Row 1 (Green color cells), i have used conditional formatting to find the missing data with subtotal-count. Similarly, I need a check for this "column I" before uploading the file whether my "column I" contains any number format or not.
Hi Rafi
Rather than find the cells that can error wouldn't it just be better & more reliable to format the entire column as general as a matter of course? Just click on column I and change all to general?
I understand why you are look for the cell type, i just wonder if you really need to
Purfleet
Hi Purfleet,
Just click on column I and change all to general? I know this very well.
I need a check to find the number format cells. Take your time and tell me if you find.
I have to agree with Purfleet.
No need to check.
Just change the entire column to the required format.
@Velouria, @Purfleet and the like,
I'm not sure saying 'rethink your approach coz using formatting to calculate is bad' is helpful. And "you really shouldnt be calculating anything on a cell format." How come you shouldn't? If it serves your use, go for it; there is nothing wrong with it.
Take this case. I am putting down figures for accomodation in a spreadsheet and I track what's paid by colouring unpaid red and paid green. I want the total cell to calculate all the red cells so I know how much is outstanding.
So you see @SunnyKow there are practical uses lol.
Thanks for the info guys
Take it easy
Hi Michael
Thanks for your feedback.
I did not say that there is no practical use in counting/summing cells with colors but there are some restrictions.
You can see the details here Calculating the Count, Sum and Average in Colored Cells
I too use a lot of colors in my reports/error-refreshing-connections-dashboard-reports (even though is is frowned upon by many) since sometimes it is part of the requirement.
In Rafi's case he wanted to count the type of cell formatting (not colors) and we only suggested other alternatives for him to explore. The final choice is his.
In your scenario if I want to track paid/unpaid amount, I would prefer to have helper columns to indicate their status.
It will allow me to analyze the data in a Pivot Table and display them on a dashboard.
There are no wrong or right ways to do what we want. It's just a matter of preference.
Happy Excelling
Cheers
Sunny
"I'm not sure saying 'rethink your approach coz using formatting to calculate is bad' is helpful. And "you really shouldnt be calculating anything on a cell format." How come you shouldn't? If it serves your use, go for it; there is nothing wrong with it."
Do you think it's more helpful to encourage someone down a path that you know from experience will cause them problems, or to suggest they adopt a different approach from the outset? Excel is not designed to calculate based on cell formats and anything you do to try and make it do so will be a convoluted workaround that probably won't work reliably since changing cell formats doesn't trigger any events you can use to force a recalculation. There is almost always a better way to set things up so that you can work with the software, not against it.
Anything I say in this, or any other, forum is simply my advice. Nobody has to take it. 🙂