【问题标题】:check for range of cells & append a cell with the data from corresponding col检查单元格范围并使用相应列中的数据附加一个单元格
【发布时间】:2016-06-28 12:39:49
【问题描述】:

检查单元格范围[比如 C1:E5],如果单元格包含一个值,则找到它的行 [比如 row-4] 附加一个单元格 [比如 B6],其中包含单元格的数据及其对应的行数据。

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    Sub Demo()
        Dim str As String
    
        str = ""
    
        For Each cel In Range("C1:E5")
            If Not IsEmpty(cel) Then
                If str = "" Then
                    str = Range("B" & cel.Row) & "=" & cel.Value
                Else
                    str = str & ", " & Range("B" & cel.Row) & "=" & cel.Value
                End If
            End If
        Next
    
        If str <> "" Then Range("B6") = str
    End Sub
    

    【讨论】:

      【解决方案2】:
      Sub test()
      
          Dim rng As Range
          Dim tmp As String
      
          Set rng = Range("C1:E5")
      
          For Each cell In rng
              If cell.Value <> "" Then
                  tmp = tmp + " " + Cells(cell.Row, 2).Value + " = " + cell.Value
              End If
          Next cell
      
          Range("B6").Value = tmp
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-15
        相关资源
        最近更新 更多