클립 보드에서 선택한 셀에 여러 줄의 데이터를 붙여 넣을 매크로가 있습니다. 각 행에 대해 새 행을 삽입합니다. A 열과 Row1 열은 머리글을 포함하며 삽입 된 행에 대해 채울 것입니다.VBA에서 클립 보드 데이터의 따옴표 정리
Sheet1
Header0 Header Header Header
Header1 Data
Header2 Data Data1
Data2 Data
Header3 Data
경우에 따라 따옴표가 추가되는 경우가 있지만 때때로 그렇지 않습니다. 합법적 인 따옴표 문자를 제거하지 않고 클립 보드 데이터를 정리할 수있는 방법이 있습니까?
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
어쩌면 꽤 중복되지는 않지만 관련이있을 수 있습니다. http://stackoverflow.com/q/24910288/4996248 –
내 경우에는 복사하는 소스를 어디에서나 볼 수 있지만 Excel 셀. 그래서 나는 클립 보드의 내용을 얻고 싶을 것입니다 (사용자가 이미 CTRL + C를 눌렀다 고 가정합니다). – Esuriency