Solved

routines dropping leading zeros

Posted on 2013-06-28
2
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

739 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