简体   繁体   English

我怎样才能使这个公式变得动态

[英]How can I make this formula dynamic

In a spreadsheet, I have five columns with the following headings 在电子表格中,我有五列,标题如下

  • "Product Code" in cell B3 单元格B3中的“产品代码”
  • "Product Description" in cell C3 C3单元中的“产品说明”
  • "Dozens per case" in cell D3 D3单元格中的“每箱数十个”
  • "Cases per pallet" in cell E3 E3单元中的“每个托盘的箱子数”
  • "UOM" in cell F3 (which means Unit of Measure) F3单元格中的“ UOM”(表示度量单位)

On my user form, I have a combo box that the user will select the product from, a command button and a text box. 在我的用户窗体上,我有一个用户可以从中选择产品的组合框,一个命令按钮和一个文本框。 The values of that combo box are populated from the spreadsheet Product Code column. 该组合框的值从电子表格的“产品代码”列中填充。

Once the user selects the product from the combo box and enters a value in the text box (called "txtbxdz") and clicks the command button, a formula will be performed. 用户从组合框中选择产品并在文本框中输入一个值(称为“ txtbxdz”)并单击命令按钮后,将执行公式。

Currently the values are hard coded into the program as shown in the formula below. 当前,这些值被硬编码到程序中,如下式所示。

Private Sub cmdbtnPrint_Click()

    Dim textValUp As Long
    Dim textValDown As Long
    Dim txtUOM As String
    Dim txtCs As Long
    Dim txtDz As Long        

        Case Is = "4120-5-01 (ALLERGY 180MG 5CT)"
            txtDz = 2
            txtCs = 200
            txtUOM = "DZ"
    End Select

    textValUp = ((txtbxdz.Value) / txtDz / txtCs) + 0.5 - 1E-16
    textValDown = ((txtbxdz.Value) / txtDz / txtCs) - 0.5 + 1E-16

End Sub

Yes, if I understand your answer correctly. 是的,如果我正确理解您的答案。 If I recall correctly what a VLookup does similar to that. 如果我没记错的话,VLookup会做什么。 Let me give an example. 让我举个例子吧。 If the user selects the 4120-5-01 (Allergy 180mg 5ct) from the combo box , an unknown line of code at this point, will loop through the product description until the code finds the product, then I guess offsets to the column that holds the values that corresponds to that product and assigns that value to the appropriate variable. 如果用户从组合框中选择4120-5-01(过敏180mg 5ct),这时未知的代码行将循环浏览产品说明,直到代码找到产品为止,我猜这是该列的偏移量保存与该产品对应的值,并将该值分配给适当的变量。 So if Product name is located in cell C3 The code will offset 1 to the right get the value of "Dozens per case" in cell D3 and assign it to txtDz and offset it again by 1 and assigns the value in E3 to txtCs and so on. 因此,如果产品名称位于单元格C3中,则代码将向右偏移1,以获取单元格D3中“每箱几十个”的值,并将其分配给txtDz,再次将其偏移1,然后将E3中的值分配给txtCs,依此类推上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM