简体   繁体   English

VBA-根据相邻单元格的数据插入行

[英]VBA - Inserting Rows Based on count of adjacent cells with data

Here is my scenario: 10 Columns from A to J, 100 rows. 这是我的情况:从A到J的10列,100行。 Each row can have any where from 1 to 10 entries. 每行可以有1到10个条目。

I need to count the number of cells with data in each row, and insert that same amount of rows beneath the row that was just counted. 我需要计算每行中包含数据的单元格的数量,并在刚刚计算的行下方插入相同数量的行。

EX: Row 1 has entries in Columns AD, then I'd need 4 rows inserted below row 1. EX2: Row 20 has entries in columns AG, then i'd need 7 rows inserted below row 20 EX:第1行在AD列中有条目,那么我需要在第1行下面插入4行。EX2:第20行在AG列中有条目,然后我需要在第20行下面插入7行

Any help is greatly apprecaited 非常感谢任何帮助

This isn't a complete answer, but hopefully it'll push you in the right direction (I'm pretty new to programming myself). 这不是一个完整的答案,但是希望它能将您推向正确的方向(我对自己编程非常陌生)。

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

This logic should work for you. 此逻辑应为您工作。 But you'll need to fix the coding. 但是您需要修复编码。

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

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