【问题标题】:Looking for Excel VBA solution to compare data寻找 Excel VBA 解决方案来比较数据
【发布时间】:2022-11-10 23:08:18
【问题描述】:

需要按 FacilityID 列比较两个 excel 文件中的数据。 Excel A 数据必须首先聚合。在 Excel B 中,FacilityID 是唯一的行。

尝试 VLOOKUP。它变得太混乱了。需要VBA解决方案

【问题讨论】:

    标签: vba


    【解决方案1】:

    515555
    515555
    906461
    906461
    926284
    926284
    926948
    1156397
    1156410
    1156418
    1156419
    1156420
    1156420
    1156472
    1174033
    1174064
    1239810
    1239837
    1239841
    1334837
    1358203
    1358203
    2162763
    2175874
    2176993
    2303380
    2303380
    2388384
    2390153
    2390727
    2392254
    2393065
    2393630
    2393675
    2395036
    2414318
    2418977
    2432964
    2464851
    2464852
    2464853
    2464854
    2481075
    2481680
    2482699
    2483625
    2484324
    2493960
    2493960
    2493963
    2501044
    2502599
    2505097
    2505097
    2505350
    2505417
    2505558
    2505558
    2505572
    2505584
    2505590
    2505796
    2505946
    2505954
    2505975
    2505975
    2509006
    2510152
    2510157
    2510158
    2520504
    2527204
    2531620
    2541306
    2541306
    2541443
    2566652
    2566964
    2569179
    2574396
    2574396
    2585065
    2585065
    1008326823DPL0000047511
    101137876141000464046
    101193407941000464046
    101206951741000464046
    101207408141006352606
    101318794741004133168
    101966704541004133168
    102177099641004133168
    102950379241004133168
    103153671141004133168
    103153671141006352606
    103308594641004133168
    103308594641006352606
    1002729535770000244651
    1011873231790000244651
    1011928842770000244651
    1012056458770000244651
    1015010173770000244651
    1015010874770000244651
    1015286195770000244651
    1018646117771000242191
    1018679457770000244651
    1018679457771000242191
    1021572957770000244651
    1022317608100000244651
    1022317608770000244651
    1025549704771000242191
    1026927451771000242191
    1026927478770000244651
    1026927478771000242191
    1029037546770000244651
    1029439369100000244651
    1029439369770000244651
    1029503776770000244651
    1029503776771000242191
    1030575195770000244651
    1030593509770000244651
    1031697294771000242191
    1032419131770000244651
    1032607647770000244651
    1033340962770000244651
    1033340997770000244651
    1033341276770000244651
    1033344526770000244651
    1033344534770000244651
    1033360513770000244651
    1035043604100000244651
    1035043639100000244651
    1035043639770000244651
    10031528513001005060000244651
    10031528513001005060000244651
    10031528513001005060000244651
    10031528943001005060000244651
    10150101733001005060000244651
    10150106613001005060000244651
    10210854953001005060000244651
    10220428463001005060000244651
    10220429193001005060000244651
    10326516973001006001028735916

    【讨论】:

      【解决方案2】:

      Sub CopyAndPasteNewSheet()
      dlastRow = ActiveSheet.Cells(Rows.Count, "I").End(xlUp).Row
       ActiveSheet.Range("I1:I" & dlastRow & " , m1:m" & dlastRow & " , o1:o" & dlastRow & " , q1:q" & dlastRow & "").Select
       Selection.Copy
       
      
       
       With ThisWorkbook
              Set ws = .Sheets.Add(After:=.Sheets(.Sheets.Count))
              ws.Name = "Optima Blue"
              ws.Paste
              ws.Range("E2").Formula = "=B2+C2+D2"
              ws.Range("E2").Copy
              ws.Range("E3:E" & dlastRow & " ").PasteSpecial (xlPasteAll)
              ws.Range("E2:E" & dlastRow & " ").NumberFormat = "#,##0"
              
          End With
          
      End Sub
      
      Sub CopyAndPasteNewSheet2()
      Dim sh2Data As Variant
      dlastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
       ActiveSheet.Range("D1:D" & dlastRow & ", AH1:AH" & dlastRow & "").Select
       Selection.Copy
       
       With ThisWorkbook
              Set ws = .Sheets.Add(After:=.Sheets(.Sheets.Count))
              ws.Name = "CRC"
              ws.Paste
              ws.Range("B2:B" & dlastRow & " ").NumberFormat = "#,##0"
              
          End With
          
      End Sub
      
      Sub FindCrc()
        Dim sh2 As Worksheet, sh3 As Worksheet
        Dim aRng, bRng As Range
        Dim Fnd As Range
        
        Set sh2 = Sheets("Optima Blue")
        Set sh3 = Sheets("CRC")
        
        aLastRow = sh2.Cells(Rows.Count, "A").End(xlUp).Row
        bLastRow = sh3.Cells(Rows.Count, "A").End(xlUp).Row
        Set aRng = sh2.Range("A2:A" & aLastRow & "")
        Set bRng = sh3.Range("A2:A" & bLastRow & "")
       
        Application.ScreenUpdating = False
        
        For Each aCell In aRng
          For Each bCell In bRng
              If aCell Is Nothing Or bCell Is Nothing Then
              ElseIf aCell.Text = bCell.Text Then
                  aCell.Offset(0, 6).Formula = "=CRC!" & bCell.Offset(0, 1).Address & " "
              Else
              End If
          Next bCell
      Next aCell
          
      
          sh2.Range("F2").Formula = "=IF(G2=0,0, ((E2-G2)/G2)*100)"
          sh2.Range("F2").Copy
          sh2.Range("F3:F" & aLastRow).PasteSpecial (xlPasteAll)
          sh2.Range("F2:F" & aLastRow).NumberFormat = "#,##0"
          
          sh2.Range("F2:F" & aLastRow).NumberFormat = "#,##0.00"
          sh2.Activate
          sh2.Range("E1") = "Sum"
          sh2.Range("F1") = "Diff in percent"
          sh2.Range("G1") = "CRC"
          
          sh2.Range("E1:g1").Interior.ColorIndex = 35
          
          Range("A1:G" & aLastRow).EntireColumn.AutoFit
          
          Range("A3:G" & aLastRow).Sort key1:=Range("F3:F" & aLastRow), order1:=xlAscending, Header:=xlNo
          
          Application.ScreenUpdating = True
          
      End Sub

      【讨论】:

        猜你喜欢
        • 2010-11-07
        • 1970-01-01
        • 2021-09-04
        • 1970-01-01
        • 1970-01-01
        • 2014-07-20
        • 2017-07-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多