尝试根据数据移动整个行

时间:2019-08-09 13:14:13

标签: excel vba

所以我的代码可以工作,但它会寻找代码AE,A,AA和AAA。当A的代码运行时,它会抓住所有它们,因为它们都以A开头。我该如何解决?

Dim rw1 As Long, lastrow1 As Long, MySel1 As Range 'Grabs skus and moves to new sheet

With Workbooks("11 Production").Worksheets("Sheet1")
    For rw1 = 1000 To 2 Step -1
        If .Cells(rw1, 2).Value Like "*Minor Novice*" And .Cells(rw1, 3).Value Like ("*A*") Then
            If MySel1 Is Nothing Then
                Set MySel1 = .Cells(rw1, 1).EntireRow

                Workbooks.Open Filename:="C:\CODE\Team Lists\11 Minor Novice A.xlsx"

            Else
                Set MySel1 = Union(MySel1, .Cells(rw1, 1).EntireRow)

            End If
        End If
    Next rw1
End With

With ThisWorkbook.Worksheets("M Novice A")
    lastrow1 = .Cells(.Rows.Count, 1).End(xlUp).Row
    If Not MySel1 Is Nothing Then
        MySel1.Copy Destination:=.Cells(lastrow1 + 1, 1)
        'MySel.Delete
    End If
End With

Dim Rng1 As Range
Set Rng1 = ThisWorkbook.Worksheets("M Novice A").Range("A1:AY300")
Rng1.Copy
Dim s111 As Workbook
Set s111 = Workbooks("11 Minor Novice A.xlsx")
Dim last1 As Long
Dim Rngnew1 As Range

With s111.Sheets("Sheet1")
    If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
        last1 = .Range("A65000").End(xlUp).Offset(1, 0).Row
    Else
        last1 = 1
    End If
End With
Set Rngnew1 = s111.Worksheets("Sheet1").Range("A" & last)

Rngnew1.PasteSpecial

期望将具有新手和A的每一行移到其自己的工作表中,但是由于C列中的所有数据均以A开头,因此会将AE,A,AA和AAA放入A工作簿中。只需知道如何设置确切的值即可,而不要使用“赞”。

0 个答案:

没有答案