Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro Help replacing dropped zeros

I have a complicated problem and I hope I can get help to write a macro
to fix it, I am dealing with the dreaded zero dropping problem, I have
tried everything, formatting as text etc, I think my problem is that in
the file exported from access, it is dropping the zeros, the numbers
appear properly in the cell but up in the formula bar the zeros are
missing, I need to cut and paste these numbers into another spreadsheet
that gets pulled into another access program. It errors out if the
zeros are missing.
If I manually add the zeros in the formula bar and put an apostrophe in
front everything works fine.
I have thousands of these numbers and they all must be 9 charachters.
These are national stock numbers, I am thinking the macro that I need
will add zeros to equal nine charachters and put an apostrophe in
front. I this possible? Some numbers may be missing 1 zero and others
may be missing 4 zeros and I need to put them back to equal 9
charachters.
I have pretty basic excel skills, anyone willing to help me with this?
I do not want to do this manually if I can help it.
Thanks,
Darrell

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Macro Help replacing dropped zeros

Hi,

Will a worksheet formula do?...

=REPT(0,9-LEN(A1)) & A1

I don't think you have to bother with the apostrophe.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Macro Help replacing dropped zeros


If I'm wrong about the apostrophe then ="'" & REPT(0,9-LEN(A1)) &A1

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Macro Help replacing dropped zeros

Darrell,
Would this suffice:

Put this formula in a helper column, copy down and then copy/paste special
values

=REPT("0",9-LEN(A1))&A1

OR

Cells formatted as text. Select you range and run macro.

Sub AddZeros()
For Each cell In Selection
cell.Value = Left("000000000", 9 - Len(cell)) & cell.Value
Next
End Sub

HTH

" wrote:

I have a complicated problem and I hope I can get help to write a macro
to fix it, I am dealing with the dreaded zero dropping problem, I have
tried everything, formatting as text etc, I think my problem is that in
the file exported from access, it is dropping the zeros, the numbers
appear properly in the cell but up in the formula bar the zeros are
missing, I need to cut and paste these numbers into another spreadsheet
that gets pulled into another access program. It errors out if the
zeros are missing.
If I manually add the zeros in the formula bar and put an apostrophe in
front everything works fine.
I have thousands of these numbers and they all must be 9 charachters.
These are national stock numbers, I am thinking the macro that I need
will add zeros to equal nine charachters and put an apostrophe in
front. I this possible? Some numbers may be missing 1 zero and others
may be missing 4 zeros and I need to put them back to equal 9
charachters.
I have pretty basic excel skills, anyone willing to help me with this?
I do not want to do this manually if I can help it.
Thanks,
Darrell


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Macro Help replacing dropped zeros

Hi,
If it has to be a macro this works if you run it after selecting the
range of cells...

Public Sub add_zeros()
Dim vaData As Variant
vaData = Selection
Dim I As Long
Dim J As Long
For I = 1 To UBound(vaData, 1)
For J = 1 To UBound(vaData, 2)
vaData(I, J) = "'" & _
WorksheetFunction.Rept("0", 9 - Len(vaData(I, J))) _
& vaData(I, J)
Next J
Next I
Selection = vaData
End Sub

Ken Johnson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro Help replacing dropped zeros

Woohoo, thanks for all the help, had to sleep for a while, Toppers
macro works fine, I cant express my appreciation, this really saved me.
Darrell

Ken Johnson wrote:
Hi,
If it has to be a macro this works if you run it after selecting the
range of cells...

Public Sub add_zeros()
Dim vaData As Variant
vaData = Selection
Dim I As Long
Dim J As Long
For I = 1 To UBound(vaData, 1)
For J = 1 To UBound(vaData, 2)
vaData(I, J) = "'" & _
WorksheetFunction.Rept("0", 9 - Len(vaData(I, J))) _
& vaData(I, J)
Next J
Next I
Selection = vaData
End Sub

Ken Johnson


Reply
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
how do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
link to combobox legepe Excel Discussion (Misc queries) 4 July 26th 06 04:45 PM
In a Macro replacing $x with ($x + i) gives x+1 not $x+1 as expe. zorro New Users to Excel 0 March 3rd 06 05:28 AM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Editing a simple macro Connie Martin Excel Worksheet Functions 5 November 29th 05 09:19 PM


All times are GMT +1. The time now is 09:45 PM.

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

About Us

"It's about Microsoft Excel"