Check if a cell contains same digits

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am looking for a way to verify if a cell say A1 contains same digits like 1111, 2222, etc.

The Len will always be 4.

Thanks in advance
 
Something like

Code:
MsgBox Range("A1").Text = String(4, Left(Range("A1").Text, 1))

Hi again,
Sorry to wake this thread up again.

But is there a way to verify with numbers like this:
0123
1234
2345
3456
4567
Etc?
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
is there a way to verify with numbers like this:
0123
1234
2345
3456
4567
Etc?
Verify what?
- That they are all 4 digits exactly?
- That they are 4 consecutive ascending digits?
- That every digit of 1234 is 1 more than every digit of the previous number (0123) etc?
- Something else?
 
Upvote 0
Yes to all the above but nothing else
 
Last edited:
Upvote 0
Yes to all the above but nothing else
Really? :huh:

So this is nothing like the previous question?

This time, instead of looking at the cells individually, we have to look at a number of cells as a group and this example would fail the verification?

Excel Workbook
A
10123
23456
31234
42345
Verify



Further, the maximum number of cells that could fit the verification is 7 and that would be these 7 cells?

Excel Workbook
A
10123
21234
32345
43456
54567
65678
76789
Verify


.. or perhaps you misunderstood what I was asking with my third point?
 
Upvote 0
Sorry I think my explanation was not clear:
This is a new form to put it; I will always have the code look at cell A1.
Then in that cell we are looking for any of those numbers as listed above. Then throw the msgbox as before. I hope this makes it clearer :)
 
Upvote 0
I will always have the code look at cell A1.
Then in that cell we are looking for any of those numbers as listed above.
So, just like data validation?
Except that "those numbers as listed above" finish with "Etc".
Where does the "Etc" end? What is the full list of valid numbers? Is it just the 7 numbers I listed in my second screen shot in post 14?
 
Upvote 0
-The full list of the numbers is supposed to be unlimited ; any number with the consecutive number form of "ABCD" is part of the list.
- "Etc" is not part of the list I used it there to show the sequence


So in cell A1, if the number has the form ABCD like 0123, 1234, ... Then we call the msgbox
 
Upvote 0
-The full list of the numbers is supposed to be unlimited ; any number with the consecutive number form of "ABCD" is part of the list.
So there has to be 4 digits and they have to be consecutive.
Unlimited list??
I'm clearly not understanding. Could you give me one more example of a 4-digit number with consecutive digits other than those 7 examples in the bottom screen shot of post 14?

Can you also confirm that the cell being looked at is formatted as Text, since 0123 would not normally show that leading zero?
 
Last edited:
Upvote 0
Yes the format will be as text.

Oh okay sorry. I think that's all the list you have up there. I didn't think through it well enough at first which made me think there could be infinite possibilities.

Yes there should be four consecutive digits
 
Upvote 0
Code:
MsgBox InStr(1, "|0123|1234|2345|3456|4567|5678|6789|", "|" & Range("A1").Text & "|") > 0

Edit: Safer would be
Code:
MsgBox InStr(1, Replace("|0123|1234|2345|3456|4567|5678|6789|", "|", Chr(0)), Chr(0) & Range("A1").Text & Chr(0)) > 0
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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