如何用vba循环不为0的单元格并拷贝到其他工作簿中
Sheet O
Sheet Q
Sheets("O").Select
Dim BillingForecast As Range
Set BillingForecast = Sheets("O").Range("13:13").Find("Forecast")
Dim BillingForecasti As Integer
Range("D2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(R[12]C[" & BillingForecast.Column - 4 & "]:R[12]C[" & lstcol - 4 & "],""<>0"")"
Dim BillingForecastMonth As Integer
For BillingForecastMonth = 1 To Sheets("O").[D2].Value - 1
Sheets("Q").Range("D9:D11").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Next
For BillingForecastj = 3 To Sheets("O").[D2].Value - 1
For BillingForecasti = BillingForecast.Column To lstcol
If Cells(14, BillingForecasti) <> 0 Then
Sheets("O").Cells(12, BillingForecasti).Copy
Sheets("Q").Cells(9, BillingForecastj).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next
Next
我想要达到的结果
希望能把Sheet O中第14行不为0的单元格,对应的第12行复制到Sheet O第9行的绿色单元格中
运行结果及报错内容
现在运行的结果如截图,只把最后一个不为0的单元格复制出来了,而且复制的位置不太对