我需要根据其他2列中的select case在列中写入值。
我的代码是:
Sub VerificaImportoMarcheCU()
Dim Cell As Range
Dim Cell2 As Range
Dim Cell3 As Range
Dim LastRow As Long
Dim DataCambioTabella As String
Sheet3.Activate
LastRow = Sheets("Dati").Range("A" & Rows.Count).End(xlUp).Row
DataCambioTabella = "27/06/2014"
For Each Cell In Sheets(3).Range("C3:C" & LastRow)
For Each Cell2 In Sheets(3).Range("G3:G" & i)
For Each Cell3 In Sheets(3).Range("Q3:Q" & LastRow)
Select Case Cell.Value
'Imposta Casistiche < 27/06/2014 e Scrivi il valore corretto nella colonna Q foglio Dati
Case Is < CDate(DataCambioTabella) And Cell2.Value >= 0 And Cell2.Value <= 1100
Debug.Print (37 + 8)
Cell3.Value = Sheets(10).Range("E3")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 1100 And Cell2.Value <= 5200
Debug.Print (85 + 8)
Cell3.Value = Sheets(10).Range("E4")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 5200 And Cell2.Value <= 26000
Debug.Print (206 + 8)
Cell3.Value = Sheets(10).Range("E5")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 26000 And Cell2.Value <= 52000
Debug.Print (450 + 8)
Cell3.Value = Sheets(10).Range("E6")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 52000 And Cell2.Value <= 260000
Debug.Print (660 + 8)
Cell3.Value = Sheets(10).Range("E7")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 260000 And Cell2.Value <= 520000
Debug.Print (1056 + 8)
Cell3.Value = Sheets(10).Range("E8")
Case Is < CDate(DataCambioTabella) And Cell2.Value > 520000
Debug.Print (1466 + 8)
Cell3.Value = Sheets(10).Range("E9")
'Imposta Casistiche > 27/06/2014
Case Is > CDate(DataCambioTabella) And Cell2.Value >= 0 And Cell2.Value <= 1100
Debug.Print (43 + 27)
Cell3.Value = Sheets(10).Range("E15")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 1100 And Cell2.Value <= 5200
Debug.Print (98 + 27)
Cell3.Value = Sheets(10).Range("E16")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 5200 And Cell2.Value <= 26000
Debug.Print (237 + 27)
Cell3.Value = Sheets(10).Range("E17")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 26000 And Cell2.Value <= 52000
Debug.Print (518 + 27)
Cell3.Value = Sheets(10).Range("E18")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 52000 And Cell2.Value <= 260000
Debug.Print (759 + 27)
Cell3.Value = Sheets(10).Range("E19")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 260000 And Cell2.Value <= 520000
Debug.Print (1214 + 27)
Cell3.Value = Sheets(10).Range("E20")
Case Is > CDate(DataCambioTabella) And Cell2.Value > 520000
Debug.Print (1686 + 27)
Cell3.Value = Sheets(10).Range("E21")
End Select
Next Cell3
Next Cell2
Next Cell
End Sub
我的问题是循环不正确,因为它永远不会出现在cell2和cell中,如果没有循环整个cell3之前。 我需要将cell,cell2和cell3循环在一起。
谢谢大家的帮助。 安德烈。