automatically fill up a cell?

  • Thread starter Thread starter polletje
  • Start date Start date
P

polletje

hello

I like to know if its possible to automatically fill up a cell with
zero's if there are less then 8 digits filled in by the user.

For example:


12345678 - stays 12345678
2345678 - becomes 02345678
345678 - becomes 00345678
11111 - becomes 00011111

etcetera

Thanx in advance
 
Here's an example with code:

Sub EightDigits()
Dim A As Integer
For A = 5 To 15
Cells(A, 5).NumberFormat = "00000000"
Next A
End Sub
 
thnx, works great. Just one little question.
When i copy and paste it in macro, in the destination file it shows
the original value. Is there a way to set the created value to a fixed
value??
 
another possibility based more on the subject title
than what you asked for in your question by way of the
examples would be to use the asterisk to define a
fill character in this case the fill character is an asterisk.
_(**$#,##0.00_);[Red]_(**$(#,##0.00);_(**$0.00_);_(@_)
 
thnx, works great. Just one little question.
When i copy and paste it in macro, in the destination file it shows
the original value. Is there a way to set the created value to a fixe
value?
 
in the workbook
=TEXT(A1,"00000000")

in VBA see "Format Function Example"
cell.value = format(myNumber,"00000000")
 
I'm not sure what you mean...but I'm guessing that this is
what you may want.

Sub EightDigitsR1()
Dim A As Integer
Dim B As Byte

For A = 5 To 15
For B = 1 To 8
If Len(Cells(A, 5).Value) = B Then
Cells(A, 5).Value = "'" & _
String(8 - B, "0") & Cells(A, 5).Value
Else
Cells(A, 5).Value = "'" & Cells(A, 5).Value
End If
Next B
Next A

End Sub
 
Back
Top