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
 

Phuoc

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

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:)
 

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