简体   繁体   English

如何排除公式返回零的单元格?

[英]How do I exclude cells where the formula returns zero?

  1. My file has four sheets.我的文件有四张。

  2. 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 公式,然后根据其他列填充(这同样适用于其他工作表)。

  3. I have it currently creating sheet1, and pasting there, then saving as a csv.我目前正在创建 sheet1,并粘贴在那里,然后保存为 csv。

  4. 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)被填充。

  5. 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) 并且从技术上讲,所有其他行都已填充。

  6. 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 语句作为测试,目前它只复制第一个填充的行,而不是第二个(但至少它也不会复制所有其他单元格为零)。

  7. 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.

相关问题 如果某些单元格未填充,我如何更正公式tat有多个IF语句返回“ #VALUE!”? - How do i correct a formula tat has multiple IF statements that returns “#VALUE!” when certain cells are not populated? 如何在Excel中创建一个公式来比较单元格中的文本并返回百分比 - How do I create a formula in excel that compares text in cells and returns a percentage 如何排除计算包含“ 0”的公式中的像元? - How to exclude calculating cells in a formula that contain “0”? 如何在公式结果中消除0(零) - How do I get rid of a 0 (zero) in my formula result 如何使Excel公式跳过空单元格 - How do I make an excel formula skip empty cells Excel:如何创建一个公式来对动态范围的单元格求和? - Excel: How do I create a formula to sum a dynamic range of cells? 如何在单独的单元格中使用多个 IF 语句创建公式? - How do I make a formula with Mulitple IF statements in seperate cells? 如何使用 Powershell 复制和粘贴没有单元格公式的单元格? - How do I copy and paste cells without cell formula with Powershell? 如何从Excel中的动态公式(SUBTOTAL + SUMPRODUCT)中排除零条目 - How to exclude zero entry from a dynamic formula (SUBTOTAL + SUMPRODUCT) in excel EXCEL公式-CountIf-如何排除满足特定条件的单元格 - EXCEL formula - CountIf - how to exclude cells that meet a certain criteria
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM