Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1752to1756
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

marta.kroll@me.com

marta.kroll@me.com
17.04.2020 13:04:21
Ledi
Hallo Zusammen,
ich habe über VBA einen Code geschrieben, der Zellen verkettet, in denen bei Spalte P ein Wert steht. Das wird für Zeile 2 bis 15 geprüft und alle Verkettungen sollen dann zum Schluss in eine Zelle geschrieben werden.
Meine Frage geht das vielleicht auch leichter? Mit einer For-Schleife?
Danke für die Hilfe.
VG

Sub Verkettung()
With Worksheets("Ein- und Ausgabe")
If .Cells(2, 16).Value  "" Then
a = .Cells(2, 4).Value & ":" & .Cells(2, 16).Value
End If
If .Cells(3, 16).Value  "" Then
b = .Cells(3, 4).Value & ":" & .Cells(3, 16).Value
End If
If .Cells(4, 16).Value  "" Then
c = .Cells(4, 4).Value & ":" & .Cells(4, 16).Value
End If
If .Cells(5, 16).Value  "" Then
d = .Cells(5, 4).Value & ":" & .Cells(5, 16).Value
End If
If .Cells(6, 16).Value  "" Then
e = .Cells(6, 4).Value & ":" & .Cells(6, 16).Value
End If
If .Cells(7, 16).Value  "" Then
f = .Cells(7, 4).Value & ":" & .Cells(7, 16).Value
End If
If .Cells(8, 16).Value  "" Then
g = .Cells(8, 4).Value & ":" & .Cells(8, 16).Value
End If
If .Cells(9, 16).Value  "" Then
h = .Cells(9, 4).Value & ":" & .Cells(9, 16).Value
End If
If .Cells(10, 16).Value  "" Then
i = .Cells(10, 4).Value & ":" & .Cells(10, 16).Value
End If
If .Cells(11, 16).Value  "" Then
j = .Cells(11, 4).Value & ":" & .Cells(11, 16).Value
End If
If .Cells(12, 16).Value  "" Then
k = .Cells(12, 4).Value & ":" & .Cells(12, 16).Value
End If
If .Cells(13, 16).Value  "" Then
l = .Cells(13, 4).Value & ":" & .Cells(13, 16).Value
End If
If .Cells(14, 16).Value  "" Then
m = .Cells(14, 4).Value & ":" & .Cells(14, 16).Value
End If
If .Cells(15, 16).Value  "" Then
n = .Cells(15, 4).Value & ":" & .Cells(15, 16).Value
End If
.Cells(2, 30).Value = a & Chr(10) & b & Chr(10) & c & Chr(10) & d & Chr(10) & e & Chr(10) & f &  _
_
_
_
Chr(10) & g & Chr(10) & h & Chr(10) & i & Chr(10) & j & Chr(10) & k & Chr(10) & l & Chr(10) & m  _
_
_
& Chr(10) & n
End With
End Sub

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Verkettung
17.04.2020 13:21:43
Ledi
Betreff upgedatet
AW: Verkettung
17.04.2020 13:34:20
MCO
Klar geht das!
Sub Feld_inhalte_verknüpfen()
Dim rng As Range, cl as range
set rng = Range("P2:P15").SpecialCells(xlCellTypeConstants)
For Each cl In rng
text = text & chr(10) & cells(cl.row,4)&":"& cl.value
Next cl
Cells(2, 30).value = text
End Sub
Gurß, MCO
Eine Email Adresse als Betreff ist Kcke...
17.04.2020 13:23:50
EtoPHG
Hallo,
VBA gut?
Probier mal:
Sub Verkettung()
Dim lRow As Long
Dim targetC As Range
With Worksheets("Ein- und Ausgabe")
Set targetC = .Cells(2, 30)
.Cells(2, 30) = ""
For lRow = 2 To 15
If .Cells(lRow, 16)  "" Then
targetC.Text = targetC.Text & _
.Cells(lRow, 4).Text & ":" & .Cells(lRow, 16).Text & vbLf
End If
Next lRow
targetC.Text = Left$(targetC, Len(targetC) - 1)
End With
End Sub

Gruess Hansueli
Anzeige
Fehlervermeidung bei alles leer!
17.04.2020 13:29:14
EtoPHG
Hallo,
Besser:
Sub Verkettung()
Dim lRow As Long
Dim targetC As Range
With Worksheets("Ein- und Ausgabe")
Set targetC = .Cells(2, 30)
targetC.ClearContents
For lRow = 2 To 15
If .Cells(lRow, 16)  "" Then
targetC.Text = targetC.Text & _
.Cells(lRow, 4).Text & ":" & .Cells(lRow, 16).Text & vbLf
End If
Next lRow
If Len(targetC.Text) > 0 Then targetC.Text = Left$(targetC, Len(targetC) - 1)
End With
End Sub
Gruess Hansueli
AW: marta.kroll@me.com
17.04.2020 13:37:16
UweD
Hallo
so

Sub Verkettung()
Dim TMP As String, i As Integer
With Worksheets("Ein- und Ausgabe")
For i = 2 To 15
If .Cells(i, 16)  "" Then
TMP = Chr(10) & TMP & .Cells(i, 4).Value & ":" & .Cells(i, 16).Value
End If
Next
.Cells(2, 30).Value = Mid(TMP, 2) 'Erstes Zeichen weg
End With
End Sub
LG UweD
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige