Excel 查找前30个字符串匹配项&;在位置A粘贴,然后在位置B粘贴剩余的字符串匹配项
这段代码将在我的一张工作表的E行中搜索单词“white”,并将该行上的名称粘贴到我的另一张工作表中。我想让它做的是粘贴x中第一个匹配的前30个匹配,剩余的匹配在第二个定义的x。而不是从第2行搜索到第30行,这正是它现在所做的。如果这不合理,标题就很简单了。谢谢Excel 查找前30个字符串匹配项&;在位置A粘贴,然后在位置B粘贴剩余的字符串匹配项,excel,vba,copy-paste,string-matching,worksheet-function,Excel,Vba,Copy Paste,String Matching,Worksheet Function,这段代码将在我的一张工作表的E行中搜索单词“white”,并将该行上的名称粘贴到我的另一张工作表中。我想让它做的是粘贴x中第一个匹配的前30个匹配,剩余的匹配在第二个定义的x。而不是从第2行搜索到第30行,这正是它现在所做的。如果这不合理,标题就很简单了。谢谢 Sub As_Of_Analysis_Sorting() Dim lr As Long, lr2 As Long, r As Long Set Sh1 = ThisWorkbook.Worksheets("All Trades") Set
Sub As_Of_Analysis_Sorting()
Dim lr As Long, lr2 As Long, r As Long
Set Sh1 = ThisWorkbook.Worksheets("All Trades")
Set Sh2 = ThisWorkbook.Worksheets("As-Of Trades")
Sh1.Select
Sh2.Cells(1, 1).Value = "Account"
Sh2.Cells(1, 2).Value = "Amount"
lr = Sh1.Cells(Rows.Count, "A").End(xlUp).row
x = 2
For r = 2 To 30
If Range("E" & r).Value = "WHITE" Then
Sh2.Cells(x, 1).Value = Sh1.Cells(r, 2).Value
Sh2.Cells(x, 2).Value = Sh1.Cells(r, 3).Value
x = x + 1
End If
Next r
x = 35
For r = 31 To lr
If Range("E" & r).Value = "WHITE" Then
Sh2.Cells(x, 1).Value = Sh1.Cells(r, 2).Value
Sh2.Cells(x, 2).Value = Sh1.Cells(r, 3).Value
x = x + 1
End If
Next r
Sh2.Select
End Sub
简直完美。谢谢你,蒂姆
Sub As_Of_Analysis_Sorting()
Dim lr As Long, lr2 As Long, r As Long, x As Long
Dim i as Long
Set Sh1 = ThisWorkbook.Worksheets("All Trades")
Set Sh2 = ThisWorkbook.Worksheets("As-Of Trades")
Sh2.Cells(1, 1).Value = "Account"
Sh2.Cells(1, 2).Value = "Amount"
lr = Sh1.Cells(Rows.Count, "A").End(xlUp).Row
x = 2
i = 0
For r = 2 To lr
If Sh1.Range("E" & r).Value = "WHITE" Then
Sh2.Cells(x, 1).Value = Sh1.Cells(r, 2).Value
Sh2.Cells(x, 2).Value = Sh1.Cells(r, 3).Value
x = x + 1
i = i + 1
If i = 30 Then x = 35
End If
Next r
Sh2.Select
End Sub