LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Using VBA to remove leading zeros

One way to get rid of leading 0's in alphanumeric data:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range
Dim iCtr As Long

With Worksheets("Sheet1")
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
For Each myCell In myRng.Cells
For iCtr = 1 To Len(myCell.Value)
If Mid(myCell.Value, iCtr, 1) < "0" Then
Exit For
End If
Next iCtr
myCell.Value = Mid(myCell.Value, iCtr)
Next myCell
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:
Open your workbook
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel and test it out--Tools|macro|macros...|Run

"Michael G. Thomas" wrote:

Yes, the data is alphanumeric unfortunately. I have the code already
though, all I need to know is how to use it. In Access, you can create a
module and then call the module using a query. Is there something similar
in Excel? Just wanna know where to put the code and how to run it.

Thanks,
Michael

On Sun, 12 Sep 2004 10:16:18 -0400, Tom Ogilvy wrote:

Nick's version will work if the data is all numeric (not alpha
numeric). Is
that the case?


--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


--

Dave Peterson

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove leading zeros Machel Excel Discussion (Misc queries) 9 February 14th 08 12:07 AM
REMOVE LEADING ZEROS ichihina Excel Worksheet Functions 2 March 14th 07 07:58 PM
Remove leading zeros from column Rich K. Excel Discussion (Misc queries) 2 January 2nd 07 09:43 PM
How to remove leading zeros using excel 2000 RodJB Excel Discussion (Misc queries) 7 December 23rd 05 02:28 AM
remove leading zeros from text strings snooze Excel Worksheet Functions 2 July 26th 05 05:59 PM


All times are GMT +1. The time now is 12:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"