Option
Explicit
Sub
Füllen()
Dim
mRng
As
Range, c
As
Range
Dim
x
As
Integer
x = 97
Cells.Clear
Set
mRng = Range(
"A1:H5"
)
For
Each
c
In
mRng
c.Formula =
String
(2, Chr(x))
x = x + 1
If
x > 122
Then
x = 97
Next
c
End
Sub
Sub
MachWas()
Const
Spalten
As
String
=
"B, G"
Const
AbZeile
As
Long
= 2
Const
ZielDatei
As
String
=
"C:\Temp\Test.txt"
Dim
lZeile
As
Long
, lSpalte
As
Long
Dim
colRng
As
Range, datRng
As
Range, c
As
Range
Dim
fso
As
Object
Dim
tso
As
Object
Dim
sgf
As
Object
Set
colRng = AuswahlBereich(Spalten)
If
colRng
Is
Nothing
Then
Exit
Sub
Set
datRng = Cells(AbZeile, colRng.Columns(1).Column)
lZeile = Cells(Rows.Count, datRng.Column).
End
(xlUp).Row
If
lZeile < AbZeile
Then
Exit
Sub
lSpalte = Cells(lZeile, Columns.Count).
End
(xlToLeft).Column
Set
datRng = Range(datRng, Cells(lZeile, lSpalte))
Set
fso = CreateObject(
"Scripting.FileSystemObject"
)
fso.CreateTextFile ZielDatei
Set
sgf = fso.GetFile(ZielDatei)
Set
tso = sgf.OpenAsTextStream(2, -2)
For
Each
c
In
datRng
If
Not
Intersect(c, colRng)
Is
Nothing
Then
tso.write c.Value & Chr(32)
Next
c
tso.Close
End
Sub
Private
Function
AuswahlBereich(
ByVal
sSpalten
As
String
)
As
Range
Dim
aSpalten()
As
String
Dim
x
As
Long
Dim
mRng
As
Range, nRng
As
Range
sSpalten = Replace(sSpalten,
" "
,
""
)
aSpalten = Split(sSpalten,
","
)
On
Error
GoTo
errorhandler
Set
mRng = Columns(Columns(aSpalten(LBound(aSpalten))).Column)
For
x = LBound(aSpalten) + 1
To
UBound(aSpalten)
Set
nRng = Columns(Columns(aSpalten(x)).Column)
Set
mRng = Union(mRng, nRng)
Next
x
Set
AuswahlBereich = mRng
On
Error
GoTo
0
Exit
Function
errorhandler:
End
Function