Solved

routines dropping leading zeros

Posted on 2013-06-28
2
223 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

803 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