如何对 Excel VBA 中的用户窗体和单元格使用嵌套 For 循环?

How can I use nested For Loop for a UserForm and Cells in Excel VBA?

我一直在尝试做一个有 28 个文本框的用户窗体,其中一半文本框是 Range("J7:J20") 的输入,另一半是 Range("K7:K20") 的输入。但是,输入不会显示在单元格中。这是代码,我将不胜感激任何帮助或建议,谢谢。

Private Sub ApplyButton_Click()
For i = 1 To 20
For j = 1 To 27 Step 2

Sheet1.Range("J" & CStr(i + 6)).Value = Me.Controls("TextBox" & CStr(j)).Value

Next j
Next i




End Sub
Private Sub ApplyButton_Click()
    Dim c As long, r As long, s As String
    ' J7:K20 Textbox1=J7 Textbox2=K7    
    For r = 0 To 13
        For c = 1 To 2
           s = "TextBox" & r * 2 + c
           Sheet1.Cells(r + 7, c + 9).Value = Me.Controls(s).Value
        Next
    Next
End Sub