“For Each”循环没有循环遍历重复ID的行

这是一个VBAmacros的一部分,它改变了从在线商店导出的订单信息,稍后将其导入到货运经理。

下面的代码正在做什么,如果满足条件,用STL1 / 2代替CRL1 / 2。

出现的问题是,将来自商店的单个订单拆分为列A中每行具有相同订单号的单独行。 macros只处理具有相同订单号的第一行。

Dim Cel7_Lastrow As Integer Cel7_Lastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row Dim Rng As Range Set Rng = Sheet2.Range("A2:A" & Cel7_Lastrow) For Each Cel7 In Rng Dim Lookup_Range2 As Range Country_Name = Cel7.Value2 C_Code = Cel7.Value2 Weight_V = Cel7.Value2 Set Lookup_Range2 = Sheet2.Range("A2:R" & Cel7_Lastrow) Country = Application.WorksheetFunction.VLookup(Country_Name,Lookup_Range2, 8, False) Code = Application.WorksheetFunction.VLookup(C_Code,Lookup_Range2, 13, False) Weight = Application.WorksheetFunction.VLookup(Weight_V,Lookup_Range2, 18, False) If Country = "GB" And Code = "CRL1" And Weight <= 0.1 Then Cel7.Offset(0, 12).Value = "STL1" End If If Country = "GB" And Code = "CRL2" And Weight <= 0.1 Then Cel7.Offset(0, 12).Value = "STL2" End If Next Cel7 

我可能会错过一些东西,但我认为一个循环会比查找更好

 Dim Cel7_Lastrow As Integer Cel7_Lastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row For r = 2 To Cel7_Lastrow If Sheet2.Cells(r, 8) = "GB" And Sheet2.Cells(r, 18) <= 0.1 Then If Sheet2.Cells(r, 13) = "CRL1" Then Sheet2.Cells(r, 13) = "STL1" If Sheet2.Cells(r, 13) = "CRL2" Then Sheet2.Cells(r, 13) = "STL2" End If Next r