此功能使用 .Find 无法完全完成
This Function Using .Find Can't Completely Finish
我有一个对象列表,需要与另一个列表进行比较;更具体地说,我需要获取此列表中的每个项目:
GAC-CR-02918
GVII-GER-2166
GVII-G600-GSN-552001
739124.003
GVII-G600-GSN-551002
GVII-G600-GSN-533001
735330.001
735750.001
GVII-GER-2309
730000.001
GVII-GER-0775
我需要在更大的项目列表中找到它们。我知道这些都在更大的列表中,因为我已经使用搜索和替换工具手动找到它们。
这是我的代码:
Function g600BurndownUser()
With Workbooks.Open(fileName:="C:\Users\u333161\Desktop\HGIs\GVII-G600 Stress Report Burndown Master (plus GSNs) 3Q Rev.xlsx", ReadOnly:=True).Worksheets(1).Range("A1:T2500")
.AutoFilter
.AutoFilter 20, "y"
.AutoFilter 13, ""
.Rows.Sort Key1:=Columns("A"), Order1:=xlAscending
.Rows.Sort Key1:=Columns("E"), Order1:=xlAscending
.Copy
End With
ThisWorkbook.Worksheets(2).Activate
ActiveSheet.Range("A1:N2500").NumberFormat = "@"
Range("A1:A2500").PasteSpecial
ThisWorkbook.Worksheets(1).Activate
Dim counter As Integer, countyBoi(1 To 100), textValue As String, offsetValue As Integer, startingPoint As Range
Set startingPoint = Range("A1:N2500").Find("Report Number"): offsetValue = 1
For counter = LBound(countyBoi) To UBound(countyBoi)
If startingPoint.Offset(offsetValue, 0).Value = "*note: only over-due G600 Cert Reports are included on this list" Then
Exit For
End If
If startingPoint.Offset(offsetValue, 0).Value <> "*note: only over-due G600 Cert Reports are included on this list" Then
ThisWorkbook.Worksheets(1).Activate
Range("A1:A2500").Select
Selection.NumberFormat = "@"
startingPoint.Offset(offsetValue, 0).Interior.Color = RGB(255, 0, 255)
textValue = startingPoint.Offset(offsetValue, 0).Value
ThisWorkbook.Worksheets(2).Range("A1:A2500").Find(textValue, LookIn:=xlValues).Interior.Color = RGB(0, 255, 255)
offsetValue = offsetValue + 1
End If
Next counter
End Function
我已经知道该代码有效,因为它突出显示了它在较小的品红色列表中经过的每个项目,以及它在较大的青色列表中找到的项目的副本。但是,我的问题在于较小列表中以 7 开头的每个项目(即 739124.003)。它将突出显示品红色项以表明它正在使用该值来找到它,但函数将在那里结束,并且找不到该值。
这里有什么我可以做的吗?非常感谢您的帮助。
只是想我会在下面添加我的潜在解决方案版本,实际上只是稍微清理了代码,删除了任何 .Activate / .Select 并用 ElseIF 更改了 If 语句,请看看它可能会派上用场:
Function g600BurndownUser()
Dim counter As Integer, countyBoi(1 To 100), textValue As String, offsetValue As Integer, startingPoint As Range
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets(1)
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Worksheets(2)
With Workbooks.Open(Filename:="C:\Users\u333161\Desktop\HGIs\GVII-G600 Stress Report Burndown Master (plus GSNs) 3Q Rev.xlsx", ReadOnly:=True).Worksheets(1).Range("A1:T2500")
.AutoFilter
.AutoFilter 20, "y"
.AutoFilter 13, ""
.Rows.Sort Key1:=Columns("A"), Order1:=xlAscending
.Rows.Sort Key1:=Columns("E"), Order1:=xlAscending
.Copy
End With
ws2.Range("A1:N2500").NumberFormat = "@"
ws2.Range("A1:A2500").PasteSpecial
Set startingPoint = ws.Range("A1:N2500").Find("Report Number")
offsetValue = 1
For counter = LBound(countyBoi) To UBound(countyBoi)
If startingPoint.Offset(offsetValue, 0).Value = "*note: only over-due G600 Cert Reports are included on this list" Then
Exit For
ElseIf startingPoint.Offset(offsetValue, 0).Value <> "*note: only over-due G600 Cert Reports are included on this list" Then
ws.Range("A1:A2500").NumberFormat = "@"
startingPoint.Offset(offsetValue, 0).Interior.Color = RGB(255, 0, 255)
textValue = startingPoint.Offset(offsetValue, 0).Value
ws2.Range("A1:A2500").Find(textValue, LookIn:=xlValues, Lookat:=xlWhole).Interior.Color = RGB(0, 255, 255)
End If
Next counter
End Function
我有一个对象列表,需要与另一个列表进行比较;更具体地说,我需要获取此列表中的每个项目:
GAC-CR-02918
GVII-GER-2166
GVII-G600-GSN-552001
739124.003
GVII-G600-GSN-551002
GVII-G600-GSN-533001
735330.001
735750.001
GVII-GER-2309
730000.001
GVII-GER-0775
我需要在更大的项目列表中找到它们。我知道这些都在更大的列表中,因为我已经使用搜索和替换工具手动找到它们。
这是我的代码:
Function g600BurndownUser()
With Workbooks.Open(fileName:="C:\Users\u333161\Desktop\HGIs\GVII-G600 Stress Report Burndown Master (plus GSNs) 3Q Rev.xlsx", ReadOnly:=True).Worksheets(1).Range("A1:T2500")
.AutoFilter
.AutoFilter 20, "y"
.AutoFilter 13, ""
.Rows.Sort Key1:=Columns("A"), Order1:=xlAscending
.Rows.Sort Key1:=Columns("E"), Order1:=xlAscending
.Copy
End With
ThisWorkbook.Worksheets(2).Activate
ActiveSheet.Range("A1:N2500").NumberFormat = "@"
Range("A1:A2500").PasteSpecial
ThisWorkbook.Worksheets(1).Activate
Dim counter As Integer, countyBoi(1 To 100), textValue As String, offsetValue As Integer, startingPoint As Range
Set startingPoint = Range("A1:N2500").Find("Report Number"): offsetValue = 1
For counter = LBound(countyBoi) To UBound(countyBoi)
If startingPoint.Offset(offsetValue, 0).Value = "*note: only over-due G600 Cert Reports are included on this list" Then
Exit For
End If
If startingPoint.Offset(offsetValue, 0).Value <> "*note: only over-due G600 Cert Reports are included on this list" Then
ThisWorkbook.Worksheets(1).Activate
Range("A1:A2500").Select
Selection.NumberFormat = "@"
startingPoint.Offset(offsetValue, 0).Interior.Color = RGB(255, 0, 255)
textValue = startingPoint.Offset(offsetValue, 0).Value
ThisWorkbook.Worksheets(2).Range("A1:A2500").Find(textValue, LookIn:=xlValues).Interior.Color = RGB(0, 255, 255)
offsetValue = offsetValue + 1
End If
Next counter
End Function
我已经知道该代码有效,因为它突出显示了它在较小的品红色列表中经过的每个项目,以及它在较大的青色列表中找到的项目的副本。但是,我的问题在于较小列表中以 7 开头的每个项目(即 739124.003)。它将突出显示品红色项以表明它正在使用该值来找到它,但函数将在那里结束,并且找不到该值。
这里有什么我可以做的吗?非常感谢您的帮助。
只是想我会在下面添加我的潜在解决方案版本,实际上只是稍微清理了代码,删除了任何 .Activate / .Select 并用 ElseIF 更改了 If 语句,请看看它可能会派上用场:
Function g600BurndownUser()
Dim counter As Integer, countyBoi(1 To 100), textValue As String, offsetValue As Integer, startingPoint As Range
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets(1)
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Worksheets(2)
With Workbooks.Open(Filename:="C:\Users\u333161\Desktop\HGIs\GVII-G600 Stress Report Burndown Master (plus GSNs) 3Q Rev.xlsx", ReadOnly:=True).Worksheets(1).Range("A1:T2500")
.AutoFilter
.AutoFilter 20, "y"
.AutoFilter 13, ""
.Rows.Sort Key1:=Columns("A"), Order1:=xlAscending
.Rows.Sort Key1:=Columns("E"), Order1:=xlAscending
.Copy
End With
ws2.Range("A1:N2500").NumberFormat = "@"
ws2.Range("A1:A2500").PasteSpecial
Set startingPoint = ws.Range("A1:N2500").Find("Report Number")
offsetValue = 1
For counter = LBound(countyBoi) To UBound(countyBoi)
If startingPoint.Offset(offsetValue, 0).Value = "*note: only over-due G600 Cert Reports are included on this list" Then
Exit For
ElseIf startingPoint.Offset(offsetValue, 0).Value <> "*note: only over-due G600 Cert Reports are included on this list" Then
ws.Range("A1:A2500").NumberFormat = "@"
startingPoint.Offset(offsetValue, 0).Interior.Color = RGB(255, 0, 255)
textValue = startingPoint.Offset(offsetValue, 0).Value
ws2.Range("A1:A2500").Find(textValue, LookIn:=xlValues, Lookat:=xlWhole).Interior.Color = RGB(0, 255, 255)
End If
Next counter
End Function