[英]If Cell Contains This or That Paste onto Another Sheet
I have 2 sheets in my workbook SheetJS
and Sheet1
.我的工作簿SheetJS
和Sheet1
有 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.