我在Excel中的一個二維表的範圍內。例如。VBA-需要創建一個函數,該函數作爲輸入
outputproduct blending combination
**5 P1:0.6/P3:0.5**
2 P1:0.3/P2:0.7
4 P5:0.4/P2:0.7
7 P11:0.7/P7:0.4
假設表格的範圍從B2:C6變化(它可以變化)。我要創建一個函數,它的第一個任務是讀這個範圍(這將是一個用戶定義的輸入),然後存儲該數據轉換成2維陣列,使得我可以在第一列和所述使用數據(整數)字符串在第二列,適當。
第一列是所得到的產物索引,而第二列是混合產品在給定的比例,結合在一起以給出在第一列中的產品。
然後是另一個表:
product index current stock updated stock
**1** **10**
2 20
**3** **50**
4 15
**5** **100**
. .
. .
. .
我有數據處理後更新此表中的股票數量。例如,當產品1與產品3以6:5(單位)的比例組合時,產生1單位的產品5。所以,我要更新的庫存量爲每個產品在表2.
任何建議,如何將範圍轉換成二維數組?
Public Function Blending_function(R1 as Range, R2 as Range)
' R2 is the range of table 2, where the updating is to be done
' R1 is first stored in to a 2 dimensional array, such that the data in the
' column 1 could be read, and the data in the column 2 could be read (of table 1).
' the integer in the column 1 of table 1 refers to the product index in table 2.
' P(i) stands for the ith product. In first row of table-1, P1 and P3 combine in the
' ratio of 6:5 to give P5. The current stock of each product is provide in table-2,
' whose range is R2(entire table 2).
' R1 is the range of table 1, from where the processing is to be done
End Function
我的主要障礙是將範圍R1(表-1)轉換爲2維數組。然後從該數組中查看輸出產品的索引,並在表2中找到該產品以更新庫存水平。
根據你的情況,應該是第二張表中'updated stock'的值? – 2012-07-10 08:59:23
@SiddharthRout喜歡在table1中,row1,限制代理是P1。因此P1的表2中的更新值是10-(10/.6),P3是50-(10/.6),P5是100 +(10/.6)。你如何繼續? – Rachit 2012-07-10 09:10:51
好吧明白了......謝謝讓我通過其餘的問題:) – 2012-07-10 09:22:09