简体   繁体   English

如果单元格包含这个或那个粘贴到另一张纸上

[英]If Cell Contains This or That Paste onto Another Sheet

I have 2 sheets in my workbook SheetJS and Sheet1 .我的工作簿SheetJSSheet1有 2 张工作SheetJS I have this code that partially matches cells in each row that contain the phrase "ABC" in SheetJS and copies them to Column D in Sheet1 .我有这个代码部分匹配每行中包含SheetJS的短语“ABC”的单元SheetJS ,并将它们复制到Sheet1 D 列。 It them partially matches cells that contain the phrase "123" in SheetJS and copies then to Column G in Sheet1 .它们部分匹配SheetJS中包含短语“123”的单元格,然后复制到Sheet1 G 列。

How can I change the code to partially match cells in each row in Sheet1 containing either "ABC" or "132" and pastes the values to Column D in Sheet1 ?如何更改代码以部分匹配Sheet1包含“ABC”或“132”的每一行中的Sheet1格,并将值粘贴到Sheet1 D 列?

I will write a similar macro to copy values into Column G in Sheet1我将编写一个类似的宏来将值复制到Sheet1 G 列Sheet1

Sub Extract_Data_or()

    For Each cell In Sheets("SheetJS").Range("A1:ZZ200")

        matchrow = cell.Row

        If cell.Value Like "*ABC*" Then 

            Sheets("Sheet1").Range("D" & matchrow).Value = cell.Value

        ElseIf cell.Value Like "*123*" Then

            Sheets("Sheet1").Range("G" & matchrow).Value = cell.Value

        End If

    Next

End Sub

Any tips will help thank you!任何提示都会有所帮助,谢谢!

Use OR logic.使用OR逻辑。

Sub Extract_Data_or()
    For Each cel In Sheets("SheetJS").Range("A1:ZZ200")
        matchrow = cel.Row

        If (cel.Value Like "*ABC*") Or (cel.Value Like "*123*") Then
            Sheets("Sheet1").Range("D" & matchrow).Value = cel.Value
        End If
    Next
End Sub

I asked for some clarifications, bun not receiving any answer I will start from the next assumptions:我要求澄清一下,bun 没有收到任何答复,我将从下一个假设开始:

Column D:D of "Sheet1" contains 200 rows filled with data. “Sheet1”的 D:D 列包含 200 行填充数据。

Private Sub Extract_Data_or_Arr()
  Dim rngArr As Variant, dArr As Variant
  Dim sh As Worksheet, i As Long, j As Long
  Dim lngOcc As Long, lngChanges As Long, boolFound As Boolean

  Set sh = Sheets("TestOcc")
   rngArr = Sheets("SheetJS").Range("A1:ZZ200").Value
   dArr = sh.Range("D1:D200").Value

    For i = 1 To UBound(rngArr, 1)
        boolFound = False
        For j = 1 To UBound(rngArr, 2)
          If InStr(rngArr(i, j), "ABC") > 0 Or InStr(CStr(rngArr(i, j)), "123") > 0 Then
              If Not boolFound Then lngChanges = lngChanges + 1
              lngOcc = lngOcc + 1: boolFound = True
              dArr(i, 1) = rngArr(i, j)
          End If
       Next j
    Next i
    sh.Range("D1:D200").Value = dArr
    MsgBox lngOcc & " occurrences, vesus " & lngChanges & " changes made."
End Sub

Finally it returns the number of occurrences versus number of changes made.最后,它返回出现次数与所做更改的次数。

暂无
暂无

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

相关问题 根据单个单元格值将项目复制/粘贴到另一个工作表上 - Copy/Paste Item onto another sheet based on a single cell value 如何清除工作表并将数据从另一工作表粘贴到工作表上 - How to clear a sheet and paste data onto it from another sheet 选择单元格中的字符串并粘贴到另一个工作表 - Select String within Cell and Paste to Another Sheet 如何:在一张纸上检索列中的最后一个单元格,然后粘贴到另一张纸上 - How to: Retrieve last cell in a column on one sheet, and paste on another sheet VBA-复制单元格并粘贴到另一张纸上的空白单元格中 - VBA - Copy cell and paste into an empty cell on another sheet 复制单元格背景颜色并将其粘贴到另一张工作表的相应单元格 - Copy cell background color and paste it to corresponding cell of another sheet 双击复制单元格并自动粘贴到另一张纸上的不同单元格 - Copy A Cell On Double Click And Paste to A Different Cell on Another Sheet Automatically 如何将每个第 n 个单元格水平转置到另一个工作表上 - How to transpose every nth cell horizontally onto another Sheet vertically 登录时将单元格值从一张纸复制到另一张纸上 - Copying cell values from one sheet onto another when logging on 从工作表中的一个单元格计算公式并将结果粘贴到另一个不同工作表的另一个不同单元格中 - Calculate a formula from one cell in a sheet and paste the result in another different cell from another different sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM