Vba 如何在一个窗体中包含两个控制变量
我有两个选择大小写取决于。值条件是否为真。如果.value=true,则使用不带扩展的用例,否则使用扩展的用例,一切似乎都正常,但是我得到了一个已经在使用的for控制变量。如何使用多个控制变量?请参阅下面的代码Vba 如何在一个窗体中包含两个控制变量,vba,excel,Vba,Excel,我有两个选择大小写取决于。值条件是否为真。如果.value=true,则使用不带扩展的用例,否则使用扩展的用例,一切似乎都正常,但是我得到了一个已经在使用的for控制变量。如何使用多个控制变量?请参阅下面的代码 If onetimeoption.value = True Then Select Case MonthComboBox.value Case "Week One" iCol = "AY" Case "Week Two"
If onetimeoption.value = True Then
Select Case MonthComboBox.value
Case "Week One"
iCol = "AY"
Case "Week Two"
iCol = "AZ"
Case "Week Three"
iCol = "BA"
Case "Week Four"
iCol = "BB"
Case "Week Five"
iCol = "BC"
Case "Week Six"
iCol = "BD"
Case "One Seven"
iCol = "BE"
Case "One Eight"
iCol = "BF"
Case "One Nine"
iCol = "BG"
Case "One Ten"
iCol = "BH"
Case "One Eleven"
iCol = "BI"
Case "One Twelve"
iCol = "BJ"
End Select
Else
nExtend = 1 'Set this as a default.
Select Case MonthComboBox.value
Case "Week One"
iCol = "AY"
nExtend = 12
Case "Week Two"
iCol = "AZ"
nExtend = 11
Case "Week Three"
iCol = "BA"
nExtend = 10
Case "Week Four"
iCol = "BB"
nExtend = 9
Case "Week Five"
iCol = "BC"
nExtend = 8
Case "Week Six"
iCol = "BD"
nExtend = 7
Case "One Seven"
iCol = "BE"
nExtend = 6
Case "One Eight"
iCol = "BF"
nExtend = 5
Case "One Nine"
iCol = "BG"
nExtend = 4
Case "One Ten"
iCol = "BH"
nExtend = 3
Case "One Eleven"
iCol = "BI"
nExtend = 2
Case "One Twelve"
iCol = "BJ"
nExtend = 1
End Select
End If
actWarehouse = Me.WarehouseComboBox.ListIndex + 1
With ws
.Cells(irow, "A").value = Me.PartTextBox.value
**For Each cel In .Cells(irow, iCol).Resize
For Each cel In .Cells(irow, iCol).Resize(, nExtend)**
cel.value = cel.value + CLng(Me.AddTextBox.value)
cel.Interior.ColorIndex = 6
Next cel
Next cel
End With
如果要使用两个for循环,只需更改目标变量名 当然,我不知道你想用每个单元格做什么-所以检查一下你想如何使用cel1和cel2-我只是猜测
For Each cel1 In .Cells(irow, iCol).Resize
For Each cel2 In .Cells(irow, iCol).Resize(, nExtend)
cel1.value = cel2.value + CLng(Me.AddTextBox.value)
cel1.Interior.ColorIndex = 6
Next cel2
Next cel1
下一个cel
行重复两次