AW: auch bei Zahlen Leerzeichen anhängen (Makro)
12.05.2006 18:07:38
Erich
Hallo André,
zum Rumprobieren:
|
Tabelle1 |
| B | C | D | E | F | G | H | I | J | K | L | M | 1 | alt | neu | Mak1 | Mak2 | Mak3 | Mak4 | Len B | Len C | Len 1 | Len 2 | Len 3 | Len 4 | 2 | | | | | | | 0 | 5 | 5 | 5 | 5 | 5 | 3 | | | | | | | 1 | 5 | 5 | 5 | 5 | 5 | 4 | a | a | a | a | a | a | 1 | 5 | 5 | 5 | 5 | 5 | 5 | ab | ab | ab | ab | ab | ab | 2 | 5 | 5 | 5 | 5 | 5 | 6 | abc | abc | abc | abc | abc | abc | 3 | 5 | 5 | 5 | 5 | 5 | 7 | abcd | abcd | abcd | abcd | abcd | abcd | 4 | 5 | 5 | 5 | 5 | 5 | 8 | abcde | abcde | abcde | abcde | abcde | abcde | 5 | 5 | 5 | 5 | 5 | 5 | 9 | abcdef | abcdef | abcdef | abcdef | abcde | abcdef | 6 | 6 | 6 | 6 | 5 | 6 | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 5 | 5 | 5 | 5 | 5 | 11 | 10 | 10 | 10 | 10 | 10 | 10 | 2 | 5 | 5 | 5 | 5 | 5 | 12 | 100 | 100 | 100 | 100 | 100 | 100 | 3 | 5 | 5 | 5 | 5 | 5 | 13 | 1000 | 1000 | 1000 | 1000 | 1000 | 1000 | 4 | 5 | 5 | 5 | 5 | 5 | 14 | 10000 | 10000 | 10000 | 10000 | 10000 | 10000 | 5 | 5 | 5 | 5 | 5 | 5 | 15 | 100000 | 100000 | 100000 | 100000 | 10000 | 100000 | 6 | 6 | 6 | 6 | 5 | 6 | 16 | 1000000 | 1000000 | 1000000 | 1000000 | 10000 | 1000000 | 7 | 7 | 7 | 7 | 5 | 7 | Formeln der Tabelle | C2 : =WENN(LÄNGE(B2)>=5;B2&"";B2&WIEDERHOLEN(" ";5-LÄNGE(B2)))
H2 : =LÄNGE(B2)
I2 : =LÄNGE(C2)
J2 : =LÄNGE(D2)
K2 : =LÄNGE(E2)
L2 : =LÄNGE(F2)
M2 : =LÄNGE(G2)
C3 : =WENN(LÄNGE(B3)>=5;B3&"";B3&WIEDERHOLEN(" ";5-LÄNGE(B3)))
H3 : =LÄNGE(B3)
I3 : =LÄNGE(C3)
J3 : =LÄNGE(D3)
K3 : =LÄNGE(E3)
L3 : =LÄNGE(F3)
M3 : =LÄNGE(G3)
|
|
|
Diagramm - Grafik - Excel Tabellen einfach im Web darstellen Excel Jeanie HTML 3.0 Download
B2 ist leer, in B3 steht ein Leerzeichen.
Und hier die 4 Makros dazu:
Option Explicit
'Wer aus Spalte B auf mind. 5 Zeichen auff[llen
Sub LeerzeicheAuffuellen1()
Dim j As Long
Columns("D").NumberFormat = "@"
For j = 2 To [B65536].End(xlUp).Row
Cells(j, 4) = Left(Cells(j, 2) _
& " ", IIf(Len(Cells(j, 2)) <= 5, 5, Len(Cells(j, 2))))
Next j
Columns("D").NumberFormatLocal = "0,00"
End Sub
Sub LeerzeicheAuffuellen2()
Dim i&, j%
Columns("E").NumberFormat = "@"
For j = 2 To [B65536].End(xlUp).Row
Cells(j, 5) = Cells(j, 2)
For i = Len(Cells(j, 5)) + 1 To 5
Cells(j, 5) = Cells(j, 5) & " "
Next i
Next j
Columns("E").NumberFormat = "General"
End Sub
Sub LeerzeicheAuffüllen3()
Dim j As Long, tmpchar As String
For j = 2 To [B65536].End(xlUp).Row
tmpchar = Cells(j, 2) & " " 'mache char + 5 blanks anhängen"
Cells(j, 6) = "'" & Mid(tmpchar, 1, 5) '1. Stelle abschneiden, next 5 nehmen
Next j
End Sub
Sub LeerzeicheAuffuellen4()
With Range(Cells(2, 7), Cells([B65536].End(xlUp).Row, 7))
.Formula = "=IF(LEN(B2)>=5,B2&"""",B2&REPT("" "",5-LEN(B2)))"
.Copy
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End With
Application.CutCopyMode = False
End Sub
Makro 4 ist wohl das schnellste.
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort