Hello there!
I've been able to solve the first half of the problem. I am exporting a multiline listbox entry (with 14 columns, I'll expand that later) by DoubleClick from one UserForm to another -
Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim MyData As DataObject
Dim i As Long
Dim strCopiedText As String
Dim dVal As Double
Set MyData = New DataObject
With Me.ListBox3
For i = 1 To .ListCount
If .Selected(i - 1) Then
strCopiedText = strCopiedText & _
.List(i - 1, 1) & vbTab & _
.List(i - 1, 0) & vbTab & _
.List(i - 1, 1) & vbTab & _
.List(i - 1, 2) & vbTab & _
.List(i - 1, 3) & vbTab & _
.List(i - 1, 4) & vbTab & _
.List(i - 1, 5) & vbTab & _
.List(i - 1, 6) & vbTab & _
.List(i - 1, 7) & vbTab & _
.List(i - 1, 8) & vbTab & _
.List(i - 1, 9) & vbCrLf
End If
Next i
If Len(strCopiedText) > 0 Then
MyData.Clear
MyData.SetText strCopiedText
MyData.PutInClipboard
End If
End With
UserForm4!TextBox1.Text = strCopiedText
UserForm4.Show
End Sub
In UserForm4 I got a Textbox (Textbox1) and tried saving the changes to the Textbox to my Excel Worksheet (Tabelle2) -
Private Sub CommandButton2_Click()
Dim ws As Worksheet, ws1 As Worksheet
Dim rng As Range
Dim lastRow As Long
Dim Ar As Variant
Dim Tb As Range
Set ws = Sheets("Tabelle2")
lastRow = ws.Cells.Find(What:="*", After:=ws.Range("A2"), _
Lookat:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Set rng = ws.Range("A2:N" & lastRow)
Set ws1 = Sheets.Add
With rng
ws.AutoFilterMode = False
.AutoFilter Field:=1, Criteria1:=TextBox1.Text
.SpecialCells(xlCellTypeVisible).Replace(ws1.Range("A1"),Textbox1.Text)
ws.AutoFilterMode = False
lastRow = ws1.Cells.Find(What:="*", After:=ws1.Range("A2"), _
Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
Ar = ws1.Range("A2:N" & lastRow)
Application.DisplayAlerts = False
ws1.Delete
Application.DisplayAlerts = True
End With
End Sub
However that does not work at all.
.SpecialCells(xlCellTypeVisible).Replace(ws1.Range("A1"),Textbox1.Text)
I was thinking I could search for the entry I'm trying to replace and then replace it with Textbox1.Text . Excel tells me I got a syntax error.
Sorry, I'm completely lost. I just cannot get Excel/Vba to determine the original entry (my database is quite big with about 14 columns of up to 400 entries each) and then replace the whole string with my Textbox text.
Thanks again for any input!
Bookmarks