清除VBA中剪贴板数据的引用

我有一个macros将粘贴到剪贴板中的选定单元格多行数据。 它会为每一行插入新行。 列A和行1包含标题,它将填充任何插入的行。

Sheet1 Header0 Header Header Header Header1 Data Header2 Data Data1 Data2 Data Header3 Data 

有时会增加额外的引号,有时候不会。 有没有办法清除剪贴板数据,而不删除合法的引号字符?

cellContent数组

 Sub ClipboardToRows() ' Split multi-lined data into separate rows for the current selection ' Assumption is that Column A contains row headers Dim currRange As Range, currCell As Range, pasteCell As Range Dim rowHeader As String Dim cellContent Dim cellStr Dim clipboard As MSForms.DataObject Dim str1 As String Set clipboard = New MSForms.DataObject clipboard.GetFromClipboard On Error GoTo clipEmpty str1 = Trim(clipboard.GetText()) Application.CutCopyMode = False Set currCell = Selection rowHeader = Cells(currCell.Row, 1).Value 'Skip Column A If (currCell.Column > 1) Then cellContent = Split(str1, Chr(10)) For i = LBound(cellContent) To (UBound(cellContent)) cellStr = Trim(cellContent(i)) If Len(cellStr) > 0 Then Set pasteCell = currCell.Offset(i) 'Set current cell with line 1 If i = 0 Then currCell.Value = cellContent(i) Else 'If next cell down is not empty or the row header is different If (Not IsEmpty(pasteCell.Value)) Or (Cells(pasteCell.Row, 1).Value <> rowHeader) Then pasteCell.EntireRow.Insert Cells(pasteCell.Row - 1, 1).Value = rowHeader End If currCell.Offset(i).Value = cellContent(i) End If End If Next End If clipEmpty: If Err <> 0 Then MsgBox "There was an issue with pasting. Please try again." End Sub 

不是真的。

如果在复制过程中将双引号不一致地添加到剪贴板中,并且在源数据中有合法的引号要保留,则无法从剪贴板中的当前内容中确切知道原始内容数据和复制过程中添加的内容。

你可以做的最好的办法是尝试识别任何引号添加不正确,并尝试删除这些。

例如,testing每个值以确定在开始和/或结束时是否有双引号,在这种情况下,从该值中删除第一个和/或最后一个字符。