【问题标题】:VBA - Inserting Rows Based on count of adjacent cells with dataVBA - 根据具有数据的相邻单元格的计数插入行
【发布时间】:2014-11-26 03:40:44
【问题描述】:

这是我的场景: 从 A 到 J 的 10 列, 100 行。每行可以有 1 到 10 个条目。

我需要计算每行中包含数据的单元格的数量,并在刚刚计算的行下方插入相同数量的行。

EX:第 1 行在 A-D 列中有条目,那么我需要在第 1 行下方插入 4 行。 EX2:第 20 行在 A-G 列中有条目,那么我需要在第 20 行下方插入 7 行

非常感谢任何帮助

【问题讨论】:

    标签: vba excel rows unpivot


    【解决方案1】:

    这不是一个完整的答案,但希望它能将您推向正确的方向(我自己对编程还是很陌生)。

    Dim RowNum as integer
    Dim ColNum as integer
    Dim NumRowsToInsert as integer
    
    
    For RowNum=100 to 1
        NumRowsToInsert=0
        For ColNum=1 to 10
            If cell  has value, then
            NumRowsToInsert=NumRowsToInsert+1
            End if
        Next ColNum    
        insert coding to insert "NumRowsToInsert" rows below row "RowNum" here
    Next RowNum
    

    这个逻辑应该适合你。但是您需要修复编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多