2016-07-29 50 views
1

我有兩個選擇案例取決於.value條件,如果它是真或假。如果.value = true,那麼在沒有擴展的情況下使用大小寫,否則你的情況下WITH擴展一切似乎工作,但是我得到一個控制變量已經在使用。我如何使用多個控制變量?請看下面的代碼如何在一個表格中有兩個控制變量

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 
+0

'下一個cel'行重複兩次 – dbmitch

回答

2

如果你想使用兩個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 
相關問題