Forum

Notifications
Clear all

Count - Based on cells format

13 Posts
5 Users
0 Reactions
244 Views
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

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.

 
Posted : 31/01/2020 1:13 pm
(@purfleet)
Posts: 412
Reputable Member
 

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

 
Posted : 31/01/2020 3:29 pm
(@debaser)
Posts: 836
Member Moderator
 

In my opinion, you'd be better off rethinking your approach. Formatting should reflect data, not be used as data.

 
Posted : 31/01/2020 6:29 pm
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

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.

 
Posted : 01/02/2020 1:59 pm
(@purfleet)
Posts: 412
Reputable Member
 

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

 
Posted : 01/02/2020 5:50 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Rafi

Just wondering why do you want to count based on cell format?

What is the practical use?

Sunny

 
Posted : 02/02/2020 11:35 am
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

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.

 
Posted : 02/02/2020 5:02 pm
(@purfleet)
Posts: 412
Reputable Member
 

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

 
Posted : 02/02/2020 6:18 pm
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

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.

 
Posted : 03/02/2020 9:32 am
(@sunnykow)
Posts: 1417
Noble Member
 

I have to agree with Purfleet.

No need to check.

Just change the entire column to the required format.

 
Posted : 03/02/2020 10:18 am
(@ari-kulai)
Posts: 1
New Member
 

@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

 
Posted : 31/01/2023 7:55 am
(@sunnykow)
Posts: 1417
Noble Member
 

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

 
Posted : 01/02/2023 1:35 am
(@debaser)
Posts: 836
Member Moderator
 

"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. 🙂

 
Posted : 01/02/2023 5:29 am
Share: