Friday 15 March 2013

excel - Assigning an array value to a variable inside a for loop in vba -


I have the following code (code 1) and it works fine. Based on the value of the combo box, it provides only the product and its price cells. I thought about using a ... loop for each of my customers to shorten the code in the case of thousands of products.

CODE 2 is my experimental excavation on this. However, when I specify the element of an array in a variable within the loop, then VBA is giving me a run-time error 1004 type mismatch? Besides, how can I accomplish my purpose for the next two ... for a two-dimensional array?

Can anyone help? I have been searching for the whole answer for the last three days and I can not find anybody thanks: -)

  "Code 1 personal sub product 1ComboBox_Change () 'fills in product and value columns If Sheet1.Product1ComboBox.Value = "1-2-3 ABC" then Sheet 1.Range ("H2"). Value = "1-2-3 ABC" sheet 1.Range ("I2"). Value = "150.00" Other Sheet1.Product1ComboBox.Value = "1-3 Pick Sticks" Then Sheet 1.Range ("H2"). Value = "1-3 Pick Sticks" Sheet 1.Range ("I2"). Value = "89.00" Elsef Sheet 1 product 1ComboBox.Value = "meat and potatoes" then sheet 1.re ("H2"). Value = "meat and potatoes" sheet 1.Range ("I2"). Value = "140.00" Elsef Sheet 1.Product 1ComboBox.Value = "Swine in a blanket" Sheet 1.Range ("H2") value = "Pigs in a blanket" sheet 1. Ranges ("I2"). Value = "140.00" Other Sheet 1. Category ("H2"). Value = "Bus Toasted" Sheet1.Range ("I2"). Value = "65.00" End if 'Sum of Uses' Sheet 1.Range ("J2") Value = Sheet 1.Range ("I2") Value * Sheet 1.Clean 1ComboBox. Value End Sub Code '2 Personal Sub Products 1ComboBox_Change () Dim Product (1 to 5) Dim I dim Product Products (1) = "1-2-3 ABC-1 50 "product (2) =" 1-3 pick-up - 89 "product (3) =" meat and potatoes - 140 "product (4) =" dip in a blanket - 140 "product (5) =" just toasted - 65 "I have product = products in each product (i) 'problem: run-time error 13 type missmatch if product (i) = sheet 1. Product 1ComboBox.Value then Sheet 1.Range ("H2"). Value = Product (i) 'Problem: Error 13 type missmatch for exit from the end if the next amount of sum is I Sheet1.Range ("J2"). Value = sheet1.range ("I2"). Value * sheet .1.QT1ComboBox.Value End Sub    

Your problem What does this specify the value of each element of the product then in return When you use the product (i) , you are effectively saying, such as product ("1-2-3 ABC-150") which strange. For <

or

     
  i = lbound (product) For each product in the  code> product if product = sheet 1. Product 1ComboBox.Value then Sheet 1.Range ("H2"). Price = Exit for Product End if Next    

No comments:

Post a Comment