Check if a cell contains same digits

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,627
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
 

Phuoc

Board Regular
Joined
Apr 29, 2016
Messages
144
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
35,504
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
35,504
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,627
@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,627
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
35,504
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,627
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:)
 

Forum statistics

Threads
1,082,065
Messages
5,362,976
Members
400,702
Latest member
oliviaalx

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top