VBA using Uppercase and LowerCase (UCase and LCase) - Code included

Поделиться
HTML-код
  • Опубликовано: 22 окт 2016
  • Grab the Free VBA Quick Reference Guide
    www.chrisjterrell.com/excel-v...
    In this video, we show you how to CONVERT TEXT TO UPPERCASE and LOWERCASE in VBA.
    One of the most annoying problems you will run into when comparing text is the that VBA considers it case sensitive (ie "This" doesn't equal "this". The solution is simple when comparing text set both text strings to either Uppercase or Lowercase.
    Code
    ========
    Sub thisandThat()
    'For Upper case
    If UCase(Range("B15")) = UCase(Range("C15")) Then
    Range("D15") = True
    Range("B16") = UCase(Range("B15"))
    Range("C16") = UCase(Range("C15"))
    Else
    Range("D15") = False
    End If
    'For Lower Case
    If LCase(Range("B15")) = LCase(Range("C15")) Then
    Range("D15") = True
    Range("B16") = LCase(Range("B15"))
    Range("C16") = LCase(Range("C15"))
    Else
    Range("D15") = False
    End If
    End Sub

Комментарии • 5

  • @SannareddyHarshavardhan547
    @SannareddyHarshavardhan547 7 лет назад

    Thank You !!

  • @kangsan2014
    @kangsan2014 3 года назад +1

    How would I do it without the useless true and false. I just want it to convert any text in a range of cells to lower or upper case? The true and false idea is cool but doesn't serve any utility.

    • @EverydayVBAExcelTraining
      @EverydayVBAExcelTraining  3 года назад +1

      Your code would look like this.
      Cells(1,1) = ucase(cells(1,1))

    • @kangsan2014
      @kangsan2014 3 года назад +2

      @@EverydayVBAExcelTraining thank you. I am a starting out programmer and a lot of lectures/teachers tend to provide a lot unnecessary content and confuse learners. I teach design with blender and when teaching people, I provide with mental tools and avoid unnecessary things. Thank you for giving script for writing it. Hopefully it will help me learn better for writing VBA for my startup company.

    • @linaseptiani2994
      @linaseptiani2994 Год назад

      @@EverydayVBAExcelTraining Hey kid. How to change the condition when people want upper case, but it will be lower case automatically when you find word such AND, IS, OR, and else.
      Ex:
      Your Fuckin' Name is Albert, and You are a True Loser.
      See??
      Okay show me your vb script, kid plz