为方程定义variables

您好,我有一个代码,检查通过一列查看任何值> 0,如果有它将复制粘贴该列表另一个它只会显示一个popup消息。

试图做的代码,但我无法定义a因此,我需要一些帮助。 在此谢谢:)

这是代码:

 Option Explicit Sub TestPasteColumnData2() Dim lastrow As Long Dim i As Long lastrow = Cells(Rows.Count, "B").End(xlUp).Row For i = 4 To lastrow a = Cells(i, "C").Value If a < 0 Then MsgBox ("No Value") Exit Sub Else Sheets("WF - L12 (3)").Columns(3).Copy Destination:=Sheets("Sheet1").Columns(3) End If Next MsgBox ("Done") End Sub Sub TestPasteColumnData3() Dim lastcol As Long Dim j As Long With Worksheets("WF - L12 (3)") lastcol = .Cells(4, Columns.Count).End(xlToLeft).Column For j = 3 To lastcol If CBool(Application.CountIfs(.Columns(j), ">0")) Then .Columns(j).Copy Destination:=Worksheets("Sheet1").Columns(3) Else MsgBox ("No Value") Exit Sub End If Next End With MsgBox ("Done") End Sub 

…通过一列检查任何值> 0,如果有的话,将复制粘贴该列到一个…

 Sub TestPasteColumnData2() With Worksheets("WF - L12 (3)") If CBool(Application.CountIfs(.Columns(3), ">0")) Then .Columns(3).Copy Destination:=Worksheets("Sheet1").Columns(3) Else MsgBox ("No Value") Exit Sub End If End With MsgBox ("Done") End Sub 
 Option Explicit Sub TestPasteColumnData2() Dim lastrow As Long Dim i As Long Dim a As Integer ' Added Declaration lastrow = Cells(Rows.Count, "B").End(xlUp).Row For i = 4 To lastrow a = Cells(i, 3).Value ' Put column no. insted of "C" If a < 0 Then MsgBox ("No Value") Exit Sub Else Sheets("WF - L12 (3)").Columns(3).Copy Destination:=Sheets("Sheet1").Columns(3) End If Next MsgBox ("Done") End Sub 

请进行上述2个更改。 你的程序应该工作。