如果单元格包含此粘贴或粘贴到另一张工作表 [英] If Cell Contains This or That Paste onto Another Sheet

查看:64
本文介绍了如果单元格包含此粘贴或粘贴到另一张工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作簿SheetJSSheet1中有2张纸.我有这段代码可以部分匹配SheetJS中包含短语"ABC"的每一行中的单元格,并将它们复制到Sheet1中的D列中.它们部分匹配SheetJS中包含短语"123"的单元格,然后复制到Sheet1中的G列.

I have 2 sheets in my workbook SheetJS and Sheet1. 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. It them partially matches cells that contain the phrase "123" in SheetJS and copies then to Column G in Sheet1.

如何更改代码以部分匹配Sheet1中包含"ABC"或"132"的每一行中的单元格并将值粘贴到Sheet1中的D列?

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

I will write a similar macro to copy values into Column G in 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

任何提示都会帮助您!

推荐答案

使用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

这篇关于如果单元格包含此粘贴或粘贴到另一张工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆