[英]How do I exclude cells where the formula returns zero?
My file has four sheets.我的文件有四张。
From all of them, I want to copy and paste column A (from A:10) (which contains a concat formula) when some other rows are populated and then save into a csv.从所有这些中,我想在填充其他一些行时复制并粘贴 A 列(来自 A:10)(其中包含一个连接公式),然后保存到 csv 中。
All rows from A10 onwards have the concat formula which is then filled in depending on the other columns (the same applies for the other sheets).从 A10 开始的所有行都有 concat 公式,然后根据其他列填充(这同样适用于其他工作表)。
I have it currently creating sheet1, and pasting there, then saving as a csv.我目前正在创建 sheet1,并粘贴在那里,然后保存为 csv。
However, from the first sheet it looks at, it takes only the first line (but the second line - J11 (and so A11) are populated.但是,从它查看的第一张纸开始,它只需要第一行(但第二行 - J11(以及 A11)被填充。
In the other sheets, it is copy and pasting the 2 rows that are populated, but also all the other rows as there are formulas there that return zero.在其他工作表中,复制并粘贴已填充的 2 行,以及所有其他行,因为那里有返回零的公式。
As I have the.End(xlDown) and technically all the other rows are populated.因为我有 .End(xlDown) 并且从技术上讲,所有其他行都已填充。
I tried an IF statement for the last sheet only as a test, and currently it only copies the first populated line, and not the second (but at least it also doesn't copy all the other cells with zero).我只为最后一张表尝试了一个 IF 语句作为测试,目前它只复制第一个填充的行,而不是第二个(但至少它也不会复制所有其他单元格为零)。
Essentially, for each sheet I'd like to loop through with for example E10 is populated, copy and paste A10 into Sheet1, etc., if E10 is not zero.本质上,对于我想循环遍历的每个工作表,例如填充 E10,如果 E10 不为零,则将 A10 复制并粘贴到 Sheet1 等中。
Sub Output_test1()
'
' Output_test1 Macro
'
'
Sheets("Create").Select
Range("A10", Range("J10").End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets.Add.Name = "Sheet1"
Sheets("Sheet1").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Assign").Select
Range("A10", Range("E10").End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A1").End(xlDown).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Date & Time").Select
Range("A10", Range("E10").End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A1").End(xlDown).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Event Type").Select
Dim rg As Range
For Each rg In Range("E10").End(xlDown)
If rg.Value > 0 Then
End If
Range("A10").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A1").End(xlDown).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
Application.CutCopyMode = False
Next
Sheets("Sheet1").Move
myTime = Format(Now, ("dd.mm.yy"))
ChDir "C:\Users\"
ActiveWorkbook.SaveAs Filename:= _
"Recruit_" & myTime & ".csv", FileFormat:=xlCSVUTF8, _
CreateBackup:=False
End Sub
There is no loop in your code not are you checking any values.您的代码中没有循环,您不是在检查任何值。 I assumed you need to check column
J
in the source sheet and copy column A
to the destination sheet.我假设您需要检查源工作表中的
J
列并将A
列复制到目标工作表。
This is a possible starting point:这是一个可能的起点:
k = 1
For i = 10 to 20
If Sheets("Source").Range("J" & i).Value = 0 then
Sheets("Destination").Range("A" & k).Value = Sheets("Source").Range("A" & i).Value
k = k + 1
End if
Next i
This only copies the value, not the formula.这只会复制值,而不是公式。 Not sure how much to explain, comment on the answer if any questions
不知道解释多少,如果有任何问题,请评论答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.