简体   繁体   English

将文字粘贴到相邻的单元格

[英]Paste text to an adjacent cell

I've been given a very large spreadsheet that would be better in a database, so I'm trying to clean up the spreadsheet so I can import it. 我得到了一个非常大的电子表格,该数据库在数据库中会更好,因此,我正在尝试清理电子表格,以便将其导入。 Throughout the sheet there are cells that have some parts that are formatted with a strike-through (indicating old or changed information). 在整个工作表中,有些单元格的某些部分已用删除线格式化(指示旧信息或更改过的信息)。 I want to cut all the strike-through out, concatenate it, and paste it into a separate "notes" column. 我想删除所有删除线,将其连接起来,然后将其粘贴到单独的“注释”列中。

I have this module ( copied from extendoffice.com website ) that will delete the strike-through, but how can I change it to copy the text and paste it into a new field? 我有这个模块( 从extendoffice.com网站复制 ),它将删除删除线,但是如何更改它以复制文本并将其粘贴到新字段中?

Sub DelStrikethroughText()
Dim xRg As Range, xCell As Range
Dim xStr As String
Dim I As Long
On Error Resume Next
Set xRg = Application.InputBox("Please select range:", "KuTools For Excel", Selection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = Fase
    For Each xCell In xRg
        If IsNumeric(xCell.Value) And xCell.Font.Strikethrough Then
            xCell.Value = ""
        ElseIf Not IsNumeric(xCell.Value) Then
            For I = 1 To Len(xCell)
                With xCell.Characters(I, 1)
                    If Not .Font.Strikethrough Then
                        xStr = xStr & .Text
                    End If
                End With
            Next
            xCell.Value = xStr
            xStr = ""
        End If
    Next
Application.ScreenUpdating = True
End Sub

You need to change the line xCell.Value = "" as this is clearing the cell. 您需要更改xCell.Value = ""因为这将清除单元格。

There are a couple of ways to do what you need: 有两种方法可以满足您的需求:

1) you can either stack the values in a string separated with a default special character between each value, then split that string into an array and paste the array into a list; 1)您可以将值堆叠在一个字符串中,并在每个值之间使用默认的特殊字符分隔,然后将该字符串拆分为一个数组并将该数组粘贴到列表中;

or the easier but a little slower way is 或者更简单但更慢的方法是

2) to paste the cell value into a separate sheet straight away, increasing row each time. 2)将单元格值直接粘贴到单独的工作表中,每次增加行数。 something like this 像这样的东西

at top of sub outside of any loops 在任何循环之外的sub顶部

Dim listRow  As Long
listRow = 1

then replace xCell.Value = "" with 然后将xCell.Value = ""替换为

Sheets("stack strike through").Cells(listRow , 1) = xCell.Value 'change sheet name, if you want to use a different column instead of A change 1 from the cells(listRow ,1)
listRow  = listRow  + 1

remembering to change sheet name 记得更改工作表名称

Sub RemoveNonStrikethroughTextFromSelection()
    Intersect(Selection.Areas(1), ActiveSheet.UsedRange).Select
    Selection.Value(11) = Replace(Replace(Selection.Value(11), "<S>", "["), "</S>", "]")
    Selection.Replace "]*[", "", xlPart
    Selection.Replace "*[", ""
    Selection.Replace "]*", ""
End Sub

This version surrounds strike-through text with [ ] , and removes the text before [ and after ] . 此版本用[ ]包围删除线文本,并删除[和之后]之前的文本。

To remove just the strike-through text, replace the 3 Selection.Replace lines with: 要仅删除删除线文本,请将3 Selection.Replace替换为:

    Selection.Replace "[*]", "", xlPart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM