VBA code to count anything number over 5 digits per row

Kingchaos64

New Member
Joined
Jan 15, 2021
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hello

I would like a code that would count all numbers over 4 digits per cell, per row and that total count per row would show up in that rows C Column.

I have a formula that kinda works but it gets easily messed up and since this will be used by other people I need something that can't be accidentally deleted or changed.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What type of data is in your cells... pure numbers or numbers mixed with text?

If numbers mixed with text, do you want to count all the digits whether they are all next to each other or not... or only 5 or more digits that are together?

You thread title says "over 5 digits" but your description says "over 4 digits"... which is it over 4 or 5 digits?
 
Upvote 0
What type of data is in your cells... pure numbers or numbers mixed with text?

If numbers mixed with text, do you want to count all the digits whether they are all next to each other or not... or only 5 or more digits that are together?

You thread title says "over 5 digits" but your description says "over 4 digits"... which is it over 4 or 5 digits?
Cells will vary between text and numbers but the cells I would like count will only have numbers in them. Sorry about that, it would be over 4 numerical digits per cell.
 
Upvote 0
Here's one way I thought of using math:

Book1
ABC
169239451
2text655 
3172737052
4990500
5548945672
625600
77467701
85058text12345 
91650012502
1092125351
Sheet1
Cell Formulas
RangeFormula
C1:C10C1=IFERROR((1*(TRUNC(LOG(A1)+1)>=4))+1*(TRUNC(LOG(B1)+1)>=4),"")
 
Upvote 0
Here's one way I thought of using math:

Book1
ABC
169239451
2text655 
3172737052
4990500
5548945672
625600
77467701
85058text12345 
91650012502
1092125351
Sheet1
Cell Formulas
RangeFormula
C1:C10C1=IFERROR((1*(TRUNC(LOG(A1)+1)>=4))+1*(TRUNC(LOG(B1)+1)>=4),"")
Wow that's some code lol.. I'll try it and see if it works for me. Thank you
 
Upvote 0
Here's one way I thought of using math:

Book1
ABC
169239451
2text655 
3172737052
4990500
5548945672
625600
77467701
85058text12345 
91650012502
1092125351
Sheet1
Cell Formulas
RangeFormula
C1:C10C1=IFERROR((1*(TRUNC(LOG(A1)+1)>=4))+1*(TRUNC(LOG(B1)+1)>=4),"")
Wait is this a formula or vba code?
 
Upvote 0
It's a formula in C1 and filled down.

If, in my example, you want C2 to be 0 and C8 to be 1, you can use

Code:
=IFERROR((1*(TRUNC(LOG(A1)+1)>=4)),0)+IFERROR(1*(TRUNC(LOG(B1)+1)>=4),0)[code]
 
Upvote 0
It's a formula in C1 and filled down.

If, in my example, you want C2 to be 0 and C8 to be 1, you can use

Code:
=IFERROR((1*(TRUNC(LOG(A1)+1)>=4)),0)+IFERROR(1*(TRUNC(LOG(B1)+1)>=4),0)[code]
Here is an array-entered** formula that will also work...
Excel Formula:
=IF(ISNUMBER(A1:B1),COUNTIF(A1:B1,">999"),0)
**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0
Hi,

May be I'm missing something...can we just use COUNTIF...

Assuming you mean Whole numbers, otherwise, just a slight modification needed for the formulas.
Also, you did say Over 4 digits, so use D1 formula, if 4 digits are to be included, than use C1 formula.

Book3.xlsx
ABCD
1692394510
2text65500
31727370520
49905000
55489456720
6256000
774677010
85058text1234510
916500125021
10921253510
11999.2999.900
121000.21000.920
139999.99999.120
1410000.110000.922
154 digits +5 digits +
Sheet760
Cell Formulas
RangeFormula
C1:C14C1=COUNTIF(A1:B1,">=1000")
D1:D14D1=COUNTIF(A1:B1,">=10000")
 
Last edited:
Upvote 0
Thank you for all the posts. I'm trying to stay clear of formulas. Would rather have a vba code if possible.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

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