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
 
@Phouc,

(y) These are both excellent and elegant solutions to the OP's first two questions! Great <del>incite</del> insight into the underlying mathematical structure of the problem!
I agree. (y)


... you can use this somewhat compact code line to do your latest check...

MsgBox [AND(LEFT(A1)=MID(A1,2,1),MID(A1,3,1)=RIGHT(A1),LEFT(A1)<>RIGHT(A1))]
.. or using Phuoc's ideas and your notation

Code:
MsgBox [AND(MOD(LEFT(A1,2),11)=0,MOD(RIGHT(A1,2),11)=0,MOD(A1,1111)>0)]
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Peter_SSs;5331191.. or using Phuoc's ideas and your notation [code said:
MsgBox [AND(MOD(LEFT(A1,2),11)=0,MOD(RIGHT(A1,2),11)=0,MOD(A1,1111)>0)][/code]
Good idea. If I am not mistaken, this can be "simplified" (using that word might be a stretch) to this...
Code:
MsgBox [(MOD(LEFT(A1,2),11)+MOD(RIGHT(A1,2),11)=0)*MOD(A1,1111)>0]
 
Upvote 0
Interesting!!!

I am really learning more and new tricks each single moments. I really appreciate that:)
 
Upvote 0
I agree. (y)


.. or using Phuoc's ideas and your notation

Code:
MsgBox [AND(MOD(LEFT(A1,2),11)=0,MOD(RIGHT(A1,2),11)=0,MOD(A1,1111)>0)]

Hi,
I just got into a trouble :


I decided to replace the "A1" with a variable from a user input and I start getting a syntax error alerts.

How do I fix that to take the variable?

Like
.....left(MyInput, 2), 11).......
I thought just taking away the square brackets will do the job yet my thinking was off the grid. :confused:
 
Upvote 0
I decided to replace the "A1" with a variable from a user input and I start getting a syntax error alerts.

I thought just taking away the square brackets will do the job yet my thinking was off the grid. :confused:

Do you remember when I said "If you are always checking only cell A1 and no other" in Message #29 ... that was because the square brackets require fixed cell references (basically, it is a shortcut notation for evaluating a formula that one might find in a cell). The square brackets are sort of an alternative method for using the Evaluate function. The Evaluate function, however, can use variables because its argument is a text string which means you can concatenate the variable into text string constants (or use VB string functions to embed the variable into the text argument) and pass that into the Evaluate function. So what Peter suggested in Message #31 could be written like this in order to use a variable instead of a cell reference.
Code:
MsgBox Evaluate(Replace("AND(MOD(LEFT(@,2),11)=0,MOD(RIGHT(@,2),11)=0,MOD(@,1111)>0)", "@", YourVariable))
Note 1: I have assumed your variable's name is YourVariable (change it an necessary)

Note 2: I used the @ symbol as a stand-in for your variable in order to avoid multiple concatenations and then used VB's Replace function to change those @ symbols to the value stored in the variable.
 
Last edited:
Upvote 0
Yes I do remember that question.
:cool:

It's fixed now.
Cheers:)
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,442
Members
448,898
Latest member
drewmorgan128

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