我编写了以下代码,如果第一列是“预测”,则填充快速计算。如果是“实际”,它需要实际配方并粘贴它以供休息。这只需要在页面上的3列发生。但是,当我运行此代码时,它一直在运行,看不到尽头。我做错了什么?
Private Sub Cancel_Click()
Dim a As Double, b As Double, c As Double
Dim b As Integer
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Forecast")
a = 0#
b = 0#
c = 0#
For b = 2 To 13
If sht.Cells(1, b).Value = "Forecast" Then
a = (Me.dAECO.Value * Me.dOSO.Value) / 1000000
b = (Me.dAECO.Value * Me.dSYN.Value) / 1000000
c = (Me.dAECO.Value * Me.dRM.Value) / 1000000
sht.Cells(6, b) = a
sht.Cells(11, b) = a
sht.Cells(28, b) = a
ElseIf sht.Cells(1, b).Value = "Actual" Then
sht.Cells(6, 2).Copy
sht.Cells(6, b).PasteSpecial xlPasteFormulas
sht.Cells(11, 2).Copy
sht.Cells(11, b).PasteSpecial xlPasteFormulas
sht.Cells(28, 2).Copy
sht.Cells(28, b).PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
End If
Next b
答案 0 :(得分:0)
Private Sub Cancel_Click()
Dim a As Double, bb As Double, c As Double
Dim b As Integer
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Forecast")
a = 0#
bb = 0#
c = 0#
For b = 2 To 13
If sht.Cells(1, b).Value = "Forecast" Then
a = (Me.dAECO.Value * Me.dOSO.Value) / 1000000
bb = (Me.dAECO.Value * Me.dSYN.Value) / 1000000
c = (Me.dAECO.Value * Me.dRM.Value) / 1000000
sht.Cells(6, b) = a
sht.Cells(11, b) = bb
sht.Cells(28, b) = c
ElseIf sht.Cells(1, b).Value = "Actual" Then
sht.Cells(6, 2).Copy
sht.Cells(6, b).PasteSpecial xlPasteFormulas
sht.Cells(11, 2).Copy
sht.Cells(11, b).PasteSpecial xlPasteFormulas
sht.Cells(28, 2).Copy
sht.Cells(28, b).PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
End If
Next b
End Sub