用户一次最多可以输入 10 个成员。A 列将是“团队名称” B 列将是“成员数量” C 列将是“成员名称” 它适用于 If Else 但对我来说做 10 次很乏味。我不知道如何将其从 If Else 更改为 For Loop
'Using If Else
Dim RowCount As Long
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
If txtNoMember.Value = 1 Then
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = txtTeamName.Text
.Offset(RowCount, 1).Value = txtNoMember.Text
.Offset(RowCount, 2).Value = txtMember01.Text
End With
ElseIf txtNoMember.Value = 2 Then
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = txtTeamName.Text
.Offset(RowCount, 1).Value = txtNoMember.Text
.Offset(RowCount, 2).Value = txtMember01.Text
.Offset(RowCount + 1, 0).Value = txtTeamName.Text
.Offset(RowCount + 1, 1).Value = txtNoMember.Text
.Offset(RowCount + 1, 2).Value = txtMember02.Text
End With
End If
'Using For Loop
Dim counter As Integer
Dim times As Integer
Dim RowCount As Long
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
For counter = 1 To txtNoMember.Value
times = txtNoMember.Value - 1
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount + times, 0).Value = txtTeamName.Text
.Offset(RowCount + times, 1).Value = txtNoMember.Text
.Offset(RowCount + times, 2).Value = txtMember01.Text
End With