Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 37

Thread: Check if a cell contains same digits

  1. #21
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,506
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    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
    There Is Always A Better Way

  2. #22
    Board Regular
    Join Date
    Apr 2016
    Location
    Vietnam
    Posts
    130
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

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

  3. #23
    Board Regular
    Join Date
    Apr 2016
    Location
    Vietnam
    Posts
    130
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by kelly mort View Post

    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

  4. #24
    Board Regular
    Join Date
    Apr 2016
    Location
    Vietnam
    Posts
    130
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by kelly mort View Post
    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

  5. #25
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,223
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by Phuoc View Post

    MsgBox Range("B1").Value Mod 1111 = 0
    Quote Originally Posted by Phuoc View Post
    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 by Rick Rothstein; Aug 24th, 2019 at 10:33 AM.
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  6. #26
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,223
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by kelly mort View Post
    How will I verify format like:
    0011
    0022
    ....
    1100
    1122
    1133
    ....
    2200
    2211
    2233
    ....

    [Code]
    Does a number like 5555 where all the digits are the same qualify as being True under this request?
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  7. #27
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,506
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    @Phuoc
    your moves are very mind blowing. Thanks

    I am learning a lot indeed.
    There Is Always A Better Way

  8. #28
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,506
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by Rick Rothstein View Post
    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.
    There Is Always A Better Way

  9. #29
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,223
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by kelly mort View Post
    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))]
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  10. #30
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,506
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Check if a cell contains same digits

    Quote Originally Posted by Rick Rothstein View Post
    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
    There Is Always A Better Way

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •