【问题标题】:excel Find copy, paste all values that start with 1Zexcel查找复制,粘贴所有以1Z开头的值
【发布时间】:2016-04-17 14:36:27
【问题描述】:

我正在尝试查找在 sheet1 中查找某些值并将这些值粘贴到 sheet2 A1 中的脚本。

  1. 范围是整个 sheet1
  2. 需要在所有单元格中搜索以“1Z”和“W”开头的任何内容
  3. 将 sheet2 中以“1Z”和“W”开头的每个单元格数据粘贴到 A 行下。

目前有这个脚本:

Sub delete_oldads()
Dim cel As Range, cfind As Range
ActiveSheet.UsedRange.Select
For Each cel In Selection
If cel = "" Then GoTo nextcel
Set cfind = cel.Find(what:="1Z", lookat:=xlPart)
If Not cfind Is Nothing Then

cfind.Copy Cells(cfind.Row, "A")
cfind.Clear
End If
nextcel:
Next cel
End Sub

但这一个复制/粘贴同一工作表中的所有匹配单元格,如果在同一行中找到匹配项,它将仅复制最后一个。

【问题讨论】:

  • 嗯...祝你好运?你的陈述背后有问题吗?

标签: excel vba


【解决方案1】:

这不使用FIND(),可能有点慢:

Sub poiuyt()
Dim K As Long, r As Range
Dim sh2 As Worksheet

Set sh2 = Sheets("Sheet2")
K = 1

With Sheets("Sheet1")
    For Each r In .UsedRange
        v = r.Value
        If v <> "" Then
            If Left(v, 1) = "W" Or Left(v, 2) = "IZ" Then
                r.Copy sh2.Cells(K, 1)
                K = K + 1
            End If
        End If
    Next r
End With
End Sub

【讨论】:

  • 我运行了你的脚本 Gary,但它什么也没做。
  • 我将“IZ”更改为“1Z”,现在它可以工作了。待会儿去测试它。
  • 谢谢!它确实需要几秒钟才能完成,但它正在做它应该做的事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-22
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多