Solved

routines dropping leading zeros

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now