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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Probably there is lots for solution, I've got something like this:
A​
B​
1
1111​
TRUE​
2
1233​
FALSE​
3
2222​
TRUE​
4
2452​
FALSE​
5
8888​
TRUE​

<tbody>
</tbody>


A​
B​
1
1111​
=SUM(CODE(MID(A1,ROW($1:$4),1)))/4=CODE(LEFT(A1,1))​
2
1233​
=SUM(CODE(MID(A2,ROW($1:$4),1)))/4=CODE(LEFT(A2,1))​

<tbody>
</tbody>


There is array formula in B1 so have to be accept with Ctrl+Shift+Enter ({} should appear) and drag it down.
 
Last edited:
Upvote 0
You did not mention about VBA in original post or thread title?

Into sheet code:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    MsgBox Evaluate("=SUM(CODE(MID(" & Target.Value & ",ROW($1:$4),1)))/4=CODE(LEFT(" & Target.Value & ",1))")
End Sub
 
Last edited:
Upvote 0
Hi, something like this?

Code:
Option Explicit


Option Explicit


Sub Worksheet_Change(ByVal Target As Range)
Dim numberInQuestion As String, firstDigitInQuestion As Long, i As Long, nextDigitInQuestion As Long, isItANumber As Boolean
If Target.Address = "$A$1" Then
numberInQuestion = Range("A1").Value
isItANumber = IsNumeric(numberInQuestion)
firstDigitInQuestion = Left(numberInQuestion, 1)
If isItANumber = True Then
For i = 1 To Len(numberInQuestion)
nextDigitInQuestion = Mid(numberInQuestion, i, 1)
If firstDigitInQuestion <> nextDigitInQuestion Then
MsgBox "numbers are different"
End If
Next i
End If
End If
End Sub


Sub init()
Dim rng As Range
Set rng = Range("A1")
Call Worksheet_Change(rng)
End Sub
 
Last edited:
Upvote 0
Okay thanks but I need a VBA code for this.
Something like
Code:
MsgBox Replace(Range("A1").Value, Left(Range("A1").Value, 1), "") = vbNullString

or
Code:
MsgBox Range("A1").Text = String(4, Left(Range("A1").Text, 1))
 
Last edited:
Upvote 0
Cool cool!!! Thank you all

I have tested all the above. They are working fine.
@Peter_SSs
your last code is very cute. Thanks
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

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