# Check if a cell contains same digits

#### kelly mort

##### Well-known Member
Great!!!!

One last request then I take a nap

How will I verify format like:
0011
0022
....
1100
1122
1133
....
2200
2211
2233
....

Code:
``MsgBox Range("A1").Text = String(4, Left(Range("A1").Text, 1))``
As the above was dealing with the whole 4 for same characters, here I want compare the first two characters for sameness then move to the last two for sameness. If both cases are true then the msgbox shows. Eg 1122 not 1123

### Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

#### Phuoc

##### Board Regular
MsgBox Range("A1").Text = String(2, Left(Range("A1").Text, 1)) & String(2, Right(Range("A1").Text, 1))

#### Phuoc

##### Board Regular

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

MsgBox Range("B1").Value Mod 1111 = 0

#### Phuoc

##### Board Regular
So in cell A1, if the number has the form ABCD like 0123, 1234, ... Then we call the msgbox
MsgBox Range("A1").Text - Left(Range("A1").Text, 1) * 1111 = 123

#### Rick Rothstein

##### MrExcel MVP

MsgBox Range("B1").Value Mod 1111 = 0
MsgBox Range("A1").Text - Left(Range("A1").Text, 1) * 1111 = 123
@Phouc,

These are both excellent and elegant solutions to the OP's first two questions! Great incite into the underlying mathematical structure of the problem!

Last edited:

#### Rick Rothstein

##### MrExcel MVP
How will I verify format like:
0011
0022
....
1100
1122
1133
....
2200
2211
2233
....

Code:
``````[/QUOTE]
Does a number like 5555 where all the digits are the same qualify as being True under this request?``````

#### kelly mort

##### Well-known Member
@Phuoc
your moves are very mind blowing. Thanks

I am learning a lot indeed.

#### kelly mort

##### Well-known Member
Does a number like 5555 where all the digits are the same qualify as being True under this request?
Thanks Rick for pointing that out. I was not able to think to that level. In that case I want it turn false .

So I think I can use the solution at post # 24 to check that. Better still I am open to more elegant options.

#### Rick Rothstein

##### MrExcel MVP
Thanks Rick for pointing that out. I was not able to think to that level. In that case I want it turn false .
If you are always checking only cell A1 and no other, 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))]

#### kelly mort

##### Well-known Member
If you are always checking only cell A1 and no other, 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))]
Okay I appreciate that

More knowledge for me to imbibe

1,102,134
Messages
5,484,929
Members
407,474
Latest member
Pam Sander

### This Week's Hot Topics

• Finding issue in If elseif else with For each Loop
Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
• MsgBox Error
Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
• CELL FORMAT - IF CONDITION
My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
• Show numbers nearly the same
Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...