我目前正在研究vba,以便在同一工作表中的列之间进行乘法和除法。
以下是我的代码
Sub test1()
Dim i As Long
For i = 3 To 100
Cells(i, 12) = (Cells(i, 8)) / (Cells(i, 6)) / 10 * 0.85
Cells(i, 13) = (Cells(i, 9)) / (Cells(i, 6)) / 10 * 0.85
Next i
End Sub
Overflow
错误。有什么建议吗?提前致谢
答案 0 :(得分:0)
您将获得一个错误,因为您的一个分区是空的
实际上,您将此公式放在L3:M100
中
=IF($F3<>"",(H3/$F3)/10*0.85,"")
可以在所有工作表中完成,如下所示
(您可以录制宏以查看此公式在VBA中的外观)
Sub ReCut()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
With ws.Range("L3:M100")
.FormulaR1C1 = "=IF(RC6<>"""",(RC[-4]/RC6)/10*0.85,"""")"
.Value = .Value
End With
Next
End Sub
答案 1 :(得分:0)
或者:
Sub M_snb()
[L3:M100] = [index(if(F3:F100="","",H3:I100/F3:F100/8.5),)]
End Sub
答案 2 :(得分:-1)
Try this
Sub test1()
Dim i, j As Integer
Dim Ws As Worksheet
For j = 1 To ThisWorkbook.Sheets.Count
Set Ws = ThisWorkbook.Sheets(j)
For i = 3 To 100
Ws.Cells(i, 12) = (Ws.Cells(i, 8)) / (Ws.Cells(i, 6)) / 10 * 0.85
Ws.Cells(i, 13) = (Ws.Cells(i, 9)) / (Ws.Cells(i, 6)) / 10 * 0.85
Next i
Next
End Sub