Check if a cell contains same digits

Peter_SSs

MrExcel MVP, Moderator
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?
 

Peter_SSs

MrExcel MVP, Moderator
Yes to all the above but nothing else
Really? :unsure:

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?
 

kelly mort

Well-known Member
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 :)
 

Peter_SSs

MrExcel MVP, Moderator
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?
 

kelly mort

Well-known Member
-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
 

Peter_SSs

MrExcel MVP, Moderator
-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:

kelly mort

Well-known Member
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
 

Peter_SSs

MrExcel MVP, Moderator
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:

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top