Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

routines dropping leading zeros

Posted on 2013-06-28
2
Medium Priority
?
229 Views
Last Modified: 2013-07-03
excel 2010 vba...

I have the following routines deleting leading zeros for some reason...

I NEED TO KEEP my leading zeros

Sub ConvertCase()

Dim rAcells As Range, rLoopCells As Range

Dim lReply As Long



    'Set variable to needed cells

    If Selection.Cells.count = 1 Then

        Set rAcells = ActiveSheet.UsedRange

    Else

       Set rAcells = Selection

    End If





    On Error Resume Next 'In case of NO text constants.

    'Set variable to all text constants

    Set rAcells = rAcells.SpecialCells(xlCellTypeConstants, xlTextValues)

   

    If rAcells Is Nothing Then

       On Error GoTo 0

       Exit Sub

    End If

         

            For Each rLoopCells In rAcells

              rLoopCells = StrConv(rLoopCells, vbUpperCase)

          Next rLoopCells

 End Sub


Sub convertupper()
    Dim rng As Range, cell As Range
    Dim lrow As Long

    lrow = Cells(Cells.Rows.count, "I").End(xlUp).Row

    Set rng = Range("I1:I" & lrow)

    For Each cell In rng
        cell.Value = UCase(cell.Value)
    Next cell

End Sub
0
Comment
Question by:Fordraiders
2 Comments
 
LVL 2

Accepted Solution

by:
arildj78 earned 2000 total points
ID: 39286015
In Sub ConvertCase() change rLoopCells = StrConv(rLoopCells, vbUpperCase) to
If Not IsNumeric(rLoopCells) Then
     rLoopCells = StrConv(rLoopCells, vbUpperCase)
End If

Open in new window

In Sub convertupper() change cell.Value = UCase(cell.Value) to
If Not IsNumeric(cell.Value) Then
     cell.Value = UCase(cell.Value)
End If

Open in new window

This should make sure that cells with numbers are left alone. Another option is to insert a ' in front of the number if it contains leading zeros. This can done like this
If IsNumeric(cell.Value) And Left(cell.Value, 1) = "0" Then
    cell.Value = Chr(39) & UCase(cell.Value)
Else
    cell.Value = UCase(cell.Value)
End If

Open in new window

0
 
LVL 3

Author Closing Comment

by:Fordraiders
ID: 39298132
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question