Check if a cell contains same digits

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,751
Office Version
2016
Platform
Windows
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
 

Some videos you may like

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
Joined
Apr 29, 2016
Messages
195
MsgBox Range("A1").Text = String(2, Left(Range("A1").Text, 1)) & String(2, Right(Range("A1").Text, 1))
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,031
Office Version
2010
Platform
Windows

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

(y) 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
Joined
Apr 18, 2011
Messages
36,031
Office Version
2010
Platform
Windows
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
Joined
Apr 10, 2017
Messages
1,751
Office Version
2016
Platform
Windows
@Phuoc
your moves are very mind blowing. Thanks

I am learning a lot indeed.
 

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,751
Office Version
2016
Platform
Windows
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
Joined
Apr 18, 2011
Messages
36,031
Office Version
2010
Platform
Windows
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
Joined
Apr 10, 2017
Messages
1,751
Office Version
2016
Platform
Windows
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:)
 

Watch MrExcel Video

Forum statistics

Threads
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...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top