2016-06-21 8 views
0

ExcelでMicrosoft Visual Basicアプリケーションエディション7.1を使用しています 2013。VBAで自己学習しましたが、今までは結果を得るために苦労しました(私はサプライチェーンマネージャーではなくIT関連の立場にある)。今私は効率の問題にも気を配りたいと思います。
Select/Activateの使用を避け、大きなブロックでデータを読み取ることについて、いくつかのヒントリストが同意しています。しかし、配列変数に保存した後に大きなブロックを検索する方法はわかりません。VBA配列変数で効率的に/ vlookupを見つける方法

マクロは実際には欠落している項目ファイルの "Sheet1"の列Aに含まれる欠落項目のリストを読み込み、3つの新しいシート(すなわち "tornio"、 "centro"、および "acquisti" (Sheet1のC列)と実動チャートファイルの両方に含まれる情報に基づいて、不足しているアイテムファイル内の " 「商品」を報告していない商品がありません。列Cの「tornio」シートまたは「centro」シートにコピーされるか、または両方とも、実写チャートファイルの内容に基づいてコピーされる。 「Prod。」を報告していない項目が不足している列Cの "acquisti"シートにコピーする必要があります。
私の非効率的なコードは次のとおりです。

Dim errore(1 To 10) 
'create a variable to store problems (i.e. missing items which are not on the production chart file) 
Do 
'start the cycle to read the missing items list which is stored in Column A 
    If Cells(i, "A") <> vbNullString Then 
    If Cells(i, "C") = "Prod." Then 
    'based on information on the missing file, prepare for division 
     sl = Cells(i, "A") 
     'store the missing item code 
     Windows("cicli.xls").Activate 
     'activate the production chart file 
     Set d = Range("C:C").Find(sl) 
     'search the missing item on the production chart file 
     If Not d Is Nothing Then 
     'if you find the missing item on the production chart file 
      j = 1 'integer 
      centro = False 'dummy 
      tornio = False 'dummy 
      Do 
      'start the cycle to read the production chart file 
       If Cells(d.Row + j, "C") = 0 Then 
       'continue as long as you find zeros (see image) 

production chart

    Select Case Left(Cells(d.Row + j, "K"), 3) 
        'based on the machine type, prepare for division 
        Case "CLO" 
         If centro = False Then 
         'if machine type is CLO then return to the missing item file and copy the current row the centro sheet 
          centro = True 
          Windows(ma).Activate 
          Sheets("Sheet1").Rows(i).Copy Destination:=Sheets("centro").Rows(c) 
          c = c + 1 
          Windows("cicli.xls").Activate 
         End If 
        Case "TCN", "TPA" 
        'if machine type is TCN or TPA then return to the missing item file and copy the current row the tornio sheet 
        If tornio = False Then 
          tornio = True 
          Windows(ma).Activate 
          Sheets("Sheet1").Rows(i).Copy Destination:=Sheets("tornio").Rows(t) 
          t = t + 1 
          Windows("cicli.xls").Activate 
         End If 
        End Select 
       j = j + 1 
       End If 
      Loop Until Cells(d.Row + j, "C") <> 0 Or Cells(d.Row + j, "C") = vbNullString 
     'close the cycle to read the production chart 
      Else: 
     'if you don't find the missing item on the production chart, please store the missing code 
      errore(e) = sl 
      e = e + 1 
     End If 
    Else: 
    'based on information on the missing file, prepare for division 
     Rows(i).Copy Destination:=Sheets("acquisti").Rows(a) 
     a = a + 1 
    End If 
End If 
Windows(ma).Activate 
'return on the missing list 
Sheets("Sheet1").Select 
i = i + 1 
Loop Until Cells(i, "B") = vbNullString 
'close the cycle to read the missing items list 

今、私は私がのために上記の検索を行うことができますどのように

Dim cicli as Variant 
    Windows("cicli.xls").Activate 
    cicli = Union(Columns("C:C"), Columns("K:K")).Value 

配列変数に生産チャートを保存することを想定そのような配列変数に項目がありませんか?

答えて

0

私は、次のいずれかが効率を達成するための最善の戦略ですが、定性的な尺度は、それが実行するマクロをかかる時間は、約44%

Workbooks.Open (laura & "pianificazione produzione\cicli.xls") 
Set ci = Range(Cells(1, "C"), Cells(Cells(Rows.Count, "C").End(xlUp).Row, "C")) 
Set ka = Range(Cells(1, "K"), Cells(Cells(Rows.Count, "K").End(xlUp).Row, "K")) 

によって減少していることを示唆し、その後起動していることを確認していませんその後、実行(Do)サイクル

Dim errore(1 To 10) 
If Cells(i, "A") <> vbNullString Then 
If Cells(i, "C") = "Prod." Then 
    sl = Cells(i, "A") 
    Set d = ci.Find(sl) 
    'now search on saved range ci rather than on production chart file 
    If Not d Is Nothing Then 
     j = 1 'integer 
     centro = False 'dummy 
     tornio = False 'dummy 
     Do 
      If ci(d.Row + j, 1) = 0 Then 
      'now continue on saved range ci rather than on production chart file 
       Select Case Left(ka(d.Row + j, 1), 3) 

[...]と

を継続
関連する問題