简体   繁体   English

Excel VBA 宏查找/剪切/粘贴

[英]Excel VBA Macro Find/Cut/Paste

I am having a difficult time coming up with a solution for a project I'm working on.我很难为我正在从事的项目提出解决方案。 I am needing a Macro to look at a specific sheet, find a specific value, and cut/paste that value at the end of the row.我需要一个宏来查看特定的工作表,找到一个特定的值,然后在行的末尾剪切/粘贴该值。

Looking at the example file I have attached, you can see that each customer has a unique ID in column A.查看我附上的示例文件,您可以看到每个客户在 A 列中都有一个唯一的 ID。

They are answering a questionnaire, and each answer they give generates a unique ID.他们正在回答问卷,他们给出的每个答案都会生成一个唯一的 ID。

The order of the answer ID's doesn't matter, as they are unique.答案 ID 的顺序无关紧要,因为它们是唯一的。 The only one that DOES matter is the answer with Semicolons.唯一重要的是分号的答案。 That answer ID needs to be the customer's last ID.该答案 ID 需要是客户的最后一个 ID。 So I need to find a way to cut these answer ID's and paste them to the end of each row.所以我需要找到一种方法来剪切这些答案 ID 并将它们粘贴到每一行的末尾。

I want the semi-colon answer to be the last answer in the array.我希望分号答案是数组中的最后一个答案。 First time posting on here so I'm sorry if the format is incorrect.第一次在这里发帖,如果格式不正确,我很抱歉。

Updated: Example File更新:示例文件

IMG1

I think that this will do what you're looking for.我认为这会做你正在寻找的。 It goes through columns and loops through each row in those columns and once it finds a cell with a ;它遍历列并循环遍历这些列中的每一行,一旦找到带有;的单元格; , it just moves that value down to the bottom of the row it was found in. ,它只是将该值向下移动到它所在行的底部。

Sub AnswerID()

    Dim lastCol As Long
    lastCol = Cells(1, Columns.count).End(xlToLeft).Column

    Dim i As Long
    For i = 1 To lastCol

        Dim lastRow As Long
        lastRow = Cells(Rows.count, i).End(xlUp).row

        Dim j As Long
        For j = 1 To lastRow
            If InStr(Cells(j, i), ";") > 0 Then
                Cells(lastRow, i).offset(1, 0).Value2 = Cells(j, i).Value2
                Cells(j, i).Value2 = vbNullString

                Exit For
            End If
        Next j

    Next i

End Sub

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

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