Ich will eine Zahlenfolge (1....100 Beispielsweise) die in einer Spalte steht ("A") in 3 gleich große Spalten aufteielen...bei ungerader Zahl soll in B1 oder B1 und C1 eine Zelle leer bleiben...
Bitte um Hilfe
mfg Daniel
Sub Aufteilen()
Dim r As Range, anzahl As Long, zweiteSpalte As Long, dritteSpalte As Long
anzahl = Range("A1").CurrentRegion.Rows.Count
zweiteSpalte = anzahl / 3
dritteSpalte = anzahl / 3 * 2
If anzahl Mod 3 = 1 Then
zweiteSpalte = zweiteSpalte + 2
ElseIf anzahl Mod 3 = 2 Then
zweiteSpalte = zweiteSpalte + 1
dritteSpalte = dritteSpalte + 1
End If
Range("A" & zweiteSpalte & ":A" & dritteSpalte).Cut Range("B1")
Range("A" & dritteSpalte + 1 & ":A" & anzahl).Cut Range("C1")
End Sub
lg,
Sam
Private Sub Ok_Click()
If Startwert = "" Then
Startwert.SetFocus
Exit Sub
ElseIf IsNumeric(Startwert) = True Then
Else
Startwert.SetFocus
Startwert = ""
Exit Sub
End If
If Endwert = "" Then
Endwert.SetFocus
Exit Sub
ElseIf IsNumeric(Endwert) = True Then
Else
Endwert.SetFocus
Endwert = ""
Exit Sub
End If
Dim lngStartwert As Long, lngEndwert As Long
With UserForm1("Ok")
lngStartwert = Startwert
lngEndwert = Endwert
End With
If lngEndwert - lngStartwert
Sub Aufteilen()
Dim r As Range, anzahl As Long, zweiteSpalte As Long, dritteSpalte As Long
anzahl = Range("A1").CurrentRegion.Rows.Count
zweiteSpalte = anzahl / 3
dritteSpalte = anzahl / 3 * 2
Select Case anzahl Mod 3
Case 0
zweiteSpalte = zweiteSpalte + 1
Case 1
zweiteSpalte = zweiteSpalte + 2
dritteSpalte = dritteSpalte + 1
Case 2
zweiteSpalte = zweiteSpalte + 1
dritteSpalte = dritteSpalte + 1
End Select
Range("A" & zweiteSpalte & ":A" & dritteSpalte).Cut Range("B1")
Range("A" & dritteSpalte + 1 & ":A" & anzahl).Cut Range("C1")
End Sub
Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden
Suche nach den besten AntwortenEntdecke unsere meistgeklickten Beiträge in der Google Suche
Top 100 Threads jetzt ansehen