• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Convert Text to Uppercase

Sep17
2007
2 Comments Written by admin

If you want to convert the text to uppercase, use the following code; however, I recommend downloading ASAP Utilities, it has many functionalities, including text conversion. It doesn’t offer source code though.

Here’s my code for uppercase conversion:
(If you want to convert your text to lowercase, replace Ucase with Lcase function in the code)

‘Will convert selected range to Upper case, using array
Sub Conv2UCase()
On Error GoTo Conv2UCase_Error

Dim vDataArr As Variant
Dim lUpperBndRow As Long, lUpperBndCol As Long
Dim lRow As Long, lCol As Long

‘store selected values in an array
vDataArr = Selection
‘get the upper bound of rows
lUpperBndRow = UBound(vDataArr, 1)
‘get the upper bound of cols
lUpperBndCol = UBound(vDataArr, 2)

‘Start a loop to go through all the elements of the array
For lRow = 1 To lUpperBndRow
    For lCol = 1 To lUpperBndCol
        ‘Check if the value is text, if not don’t convert
        If WorksheetFunction.IsText(vDataArr(lRow, lCol)) Then
            ‘Convert values to upper case
            vDataArr(lRow, lCol) = UCase(vDataArr(lRow, lCol))
        End If
    Next lCol
Next lRow
‘Return the converted values to the range
Selection = vDataArr
Exit Sub

Conv2UCase_Error:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in Sub:Conv2UCase”
End Sub

Related posts:

  1. Access VBA: Convert Access tables to arff format
  2. Concatenate function
  3. Flip row or column
  4. Range Concatenation with a character
  5. A function to reverse a string
Posted in String Operations, Uncategorized, Useful Procedures - Tagged excel, UDF, VBA
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Excel Books
» Excel Training Handout

2 Comments

  1. Anonymous's Gravatar Anonymous
    December 20, 2007 at 5:14 pm | Permalink

    What a poor effort. Messy, too many variables, slow. Just do this:
    ‘Will convert selected range to Upper case
    Sub Conv2UCase()
    Dim vCell As Variant

    For Each vCell In Selection
    vCell.Value = UCase(vCell.Value)
    Next
    End Sub

  2. Ashutosh's Gravatar Ashutosh
    December 20, 2007 at 6:16 pm | Permalink

    Anon: True.

    I just wanted to demonstrate the use of array, and this was probably when I was new to VBA. BTW, your code is slightly inefficient too. Instead of having a cell dimmed as variant, it should be rngCell as Range.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects
  • Rwill on Access Export to Excel (2007)
  • Bharathi on The search key was not found in any record in Access
  • Michael on The search key was not found in any record in Access

Related Posts

  1. Access VBA: Convert Access tables to arff format
  2. Concatenate function
  3. Flip row or column
  4. Range Concatenation with a character
  5. A function to reverse a string

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info