代码运行不准确,公式为:
F(细胞)= G(细胞)-A2仅当F(细胞)> 0
Private Sub Button_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As range
Call TrimExcessSpaces
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End If
End Sub
当代码运行并在F的单元格中找到任何“空白”或“0”值时,代码停止工作,尽管下一个F.cell可能具有正值。关键是如果下一个单元格具有正值,我们需要代码继续工作。
答案 0 :(得分:1)
当您尝试根据列F值填充列G时,实际上只需要一行代码。
在下面的示例代码中,您只需要在主子例程中调用子PopulateColumnG。
主要子例程:
Private Sub Button_Click()
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
Call PopulateColumnG
'Rest of your code
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
填充G列所需的代码:
Sub PopulateColumnG()
Dim lr As Long
lr = Cells(Rows.Count, 6).End(xlUp).Row
Range("G1:G" & lr).Formula = "=IF(F1>0,F1-$A$2,"""")"
Range("G1:G" & lr).Value = Range("G1:G" & lr).Value
End Sub