简体   繁体   English

如何在Excel中创建报告,以将空白单元格标记为“ n”,并将任何输入单元格标记为“ y”,以表示一系列单元格?

[英]How do I create a report in Excel marking empty cells as “n” and cells with any input as “y” for a range of cells?

As an example, say I have five columns and five rows of data. 例如,假设我有五列和五行数据。 Column A would all be names, where the remaining four columns, B through E, include user-generated data about each individual person. 列A都是名字,其余的四列(从B到E)包括用户生成的有关每个人的数据。

I want to create a report whereby I can preserve the name column, but for the remaining columns, simply automate a "y" or "n" output depending on if the fields were left blank or not, essentially being Person A filled out this category, or didn't fill out another, etc. 我想创建一个报告,以便保留name列,但对于其余的列,只需根据字段是否保留为空白即可自动执行“ y”或“ n”输出,本质上是填写此类别的人员A ,或者没有填写其他内容,等等。

Basically to turn this: 基本上要转这个:

[person a][populated cell][populated cell][blank cell][blank cell][populated cell]

into: 变成:

[person a][y][y][n][n][y]

Is this possible just within Excel itself? 这可能仅在Excel本身内吗? Any help would be much appreciated. 任何帮助将非常感激。

Select the worksheet and run this macro: 选择工作表并运行此宏:

Sub Yes_No()
    Dim RR As Range, N As Long
    N = Cells(Rows.Count, 1).End(xlUp).Row
    Set RR = Range("B1:E" & N)
    For Each r In RR
        If r.Value = "" Then
            r.Value = "no"
        Else
            r.Value = "yes"
        End If
    Next r
End Sub

EDIT#1 编辑#1

To produce a report on a separate sheet, create a new worksheet called Report, then select the original sheet and run this macro: 要在单独的工作表上生成报告,请创建一个名为“报告”的新工作表然后选择原始工作表并运行此宏:

Sub Yes_No()
    Dim RR As Range, N As Long, rs As Worksheet, _
        ady As String
    N = Cells(Rows.Count, 1).End(xlUp).Row
    Set RR = Range("B1:E" & N)
    Set rs = Sheets("Report")
    For Each r In RR
        ady = r.Address
        If r.Value = "" Then
            rs.Range(ady).Value = "no"
        Else
            rs.Range(ady).Value = "yes"
        End If
    Next r
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM