在庫システムのダッシュボードを作成しようとしています。ダッシュボードには、その日の売上(カテゴリ1)、購入が必要な購入(カテゴリ2)、予想される購買発注(Cateogry 3)、仕掛品(カテゴリ4)が表示されます。この質問では、カテゴリ2、購入が必要な購入のみに焦点を絞るつもりです。VBA:「移動範囲」のあるワークシートから別のワークシートへのデータの転送
ワークシート(「購入」)からカテゴリ2のダッシュボードにすべてのデータを転送しようとしています。これは、各カテゴリの範囲がアイテムによって変動するため、名前付き範囲を使用しようとしています。追加/削除されました。私はhereで働いているワークブックのサンプルを見つけることができます - それはexcelforum.comにあります。
以下のコードは私がこれまで持っているものです。これはある程度は機能しますが、Cell $ A $ 8のRange( "PurchaseStart")はA:1から始まります。私が探している名前の範囲だけを選択する方法がわかりません。私はカットオフを意味するために各行の最後に "End#"ステートメントを追加し、トリックへの希望は特定のカテゴリの範囲を選択することに秀でています。
Option Explicit
Sub purchPull()
Dim Dashboard As Worksheet
Dim Purchasing As Worksheet
Dim PM As Range, D As Range, Rng As Range
Dim purchName As Range
Set Purchasing = Worksheets("Purchasing")
Set Dashboard = Worksheets("Dashboard")
' Go through each Item in Purchasing and check to see if it's anywhere within the named range "PurchaseStart"
' In this case it should be "A8:A9" - as there is nothing in the dasboard yet
For Each PM In Purchasing.Range(Purchasing.Cells(1, 1), Purchasing.Cells(Purchasing.Rows.Count, 1).End(xlUp))
With Dashboard.Range("PurchaseStart", Dashboard.Cells(Dashboard.Rows.Count, 1))
Set Rng = .Find(What:=PM.Offset(0, 1), _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
' Do nothing, as we don't want duplicates
Else
' From the start of the named range, transfer data over - THIS IS THE PROBLEM AREA
With Dashboard.Range("PurchaseStart", Dashboard.Cells(.Rows.Count, 1)).End(xlUp)
.Offset(1, 1) = PM.Offset(0, 0) ' Order Number
.Offset(1, 2) = PM.Offset(0, 1) ' SKU
.Offset(1, 3) = PM.Offset(0, 3) ' Qty
.Offset(1, 4) = PM.Offset(0, 4) ' Date
End With
End If
End With
Next
End Sub