对于有function错误的下一个循环

我正在尝试创build一个循环来更新一些已经在Userform上创build的“TextBox”。 问题是,当我连接线

For y = 2 * (3 + k) To 2 * (3 + k) 

  For k = 0 To 7 

我得到一个不匹配的错误。 但是,如果我定义y = 6,一切都很好。

你能帮我吗?

请看下面的整个代码:

  Sub Update_TextBox_Preco() Dim k As Double Dim myarray2 As Variant Dim y As Double Dim Textbox As String Dim Textbox_1 As String Dim line As Variant Array with contained TextBox names myarray2 = Array("TextBox_Moeda_Atual", "TextBox_Medida_Atual", "TextBox_Acond_Atual", "TextBox_Lote_Atual", _ "TextBox_Incoterm_Atual", "TextBox_p_liq_atual", "TextBox_encargo_atual", "TextBox_Frete_Atual") For k = 0 To 7 Textbox = myarray2(k) For y = 2 * (3 + k) To 2 * (3 + k) UserForm1.Controls(Textbox).Value = Worksheets("PANEL").Cells(y, 45).Value Next y Next k End Sub 

只要摆脱y循环。 它只触发一次,所以每次你通过k循环时只设置y

 Sub Update_TextBox_Preco() Dim k As Long Dim myarray2 As Variant Dim y As Long Dim TextBoxUp As String Dim Textbox_1 As String Dim line As Variant 'Array with contained TextBox names myarray2 = Array("TextBox_Moeda_Atual", "TextBox_Medida_Atual", "TextBox_Acond_Atual", "TextBox_Lote_Atual", _ "TextBox_Incoterm_Atual", "TextBox_p_liq_atual", "TextBox_encargo_atual", "TextBox_Frete_Atual") For k = 0 To 7 TextBoxUp = myarray2(k) y = 2 * (3 + k) UserForm1.Controls(TextBoxUp).Value = Worksheets("PANEL").Cells(y, 45).Value Next k End Sub