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)
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
配列変数に生産チャートを保存することを想定そのような配列変数に項目がありませんか?