每个循环都很复杂

时间:2018-10-08 20:26:29

标签: excel excel-vba

因此,我有一个大数据集,其中包含制成品的价格,然后是构成该制成品的物品的价格。我正在尝试在VBA中编写代码,使我可以将制成品的价格与组成制成品的所有物品的价格进行比较。唯一的问题是,制成品中物品的数量不同,因此很难抓住两者,因为它们之间的行数不一定总是相同。因此,我的问题是有一种方法可以在数字旁边创建两个标识符,然后让代码在其旁边获取数字并进行比较。以下是几件成品及其物品。我当时在想可以为每个循环编写一个,因此如果我创建标识符,它可以循环比较过程。我刚刚开始学习VBA,这种方式使我不知所措,因此,如果您对如何实现这一点有任何想法,将不胜感激。谢谢!

W0003662    1537244 1           DUCTWORK 42148 14X8 VOLUME DAM  $4.25   $0.00 
            1648481 1   5X7 POLY BAG-4ML. 1/4 HANG HOL          $0.09   $0.09 
            1653390 1   PP WINDSOR HDL -LG - SMOKE ONL          $3.00   $0.00 
            44135   1   CPVC RED TEE 3/4X3/4X1/2" CTS           $0.72   $0.00 
                        TRC 
    Total Rep   Cost........    .......:                        $3.82


W0000312    1642273 1           PACKING WASHER ASST / 10266 $0.21   $0.21 
            1642263 1   501 SOLUTION PACKING / 10253        $0.05   $0.05 
            1642264 1   502 SOLUTION PACKING / 10254        $0.05   $0.07 
            1642265 1   503 SOLUTION PACKING / 10255        $0.05   $0.05 
            1642266 1   504 SOLUTION PACKING / 10256        $0.05   $0.05 
            1648471 1   3X4 POLY BAG-4ML. 1/4 HANG HOL      $0.01   $0.01 
                        _________   
    Total Rep   Cost........    .......:                    $0.21   


W0000316    1642329 1           ISE CONNECTION CLAMP & FLEX CO  $3.84   $3.84 
            1648475 1   4X6 POLY BAG 4ML.SEAL TOP 1/4           $0.02   $0.02 
            1652000 1   ISE CONNECTION CLAMP / ISE7470          $0.61   $0.61 
            1652001 1   INSINKERATOR FLEX COUPLING / I          $3.21   $3.21 
                        _________   
    Total Rep   Cost........    .......:                        $3.84   

W0002538    1642335 1           WHIRLAWAY DISP.SPLASH GUARD /   $0.57   $0.57 
            1648475 1   4X6 POLY BAG 4ML.SEAL TOP 1/4           $0.02   $0.02 
            1642336 1   WHIRLAWAY DISP.SPLASH GUARD X           $0.55   $0.55 
                        _________   
    Total Rep   Cost........    .......:                        $0.57   

VBA代码:

Sub CompareWipCost()
Dim TRC As Range
Dim test_wip As Worksheet
Set test_wip = ActiveSheet
Set TRC = Selection

For Each TRC In test_wip

    If TRC.Offset(1, 0).Value = 3.815 Then
        With Selection.Interior
            .Color = 65535
        End With
    Else
        With Selection.Interior
            .Pattern = xlNone
        End With
    End If
Next
End Sub

1 个答案:

答案 0 :(得分:0)

只是一个简短的想法(注意更改“ sheet2”以反映工作表的名称)

Exception in thread "main" java.lang.ClassNotFoundException: SalesCountry
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:311)
at org.apache.hadoop.util.RunJar.main(RunJar.java:232)