1

我有大约 100 张桌子。我需要在每个 % 之后为每个表插入行。如何使用 excel 宏执行此操作?

        'Total  `Banglore`  `Delhi`

Q1。年龄

Base '653 '77' '86'

18-19 '35' '15' ''22'

      '5%  '19%  '26%'

20-24 '216' '30' '33'

      '33%   '3    '38%' 

谢谢,

塔努维

4

1 回答 1

1

这可能会有所帮助: 编辑在 OP 请求中添加的一些评论。

Sub Insert_blank_rows()

    Dim i As Long
    Dim LastRow As Long
        'this code will run from last till first row which is required when inserting rows
        'here we check last not-empty row to know which point to start from
        LastRow = Cells(Rows.Count, 1).End(xlUp).Row

        'start the loop from last not-empty direction first row
    For i = LastRow To 1 Step -1
        'if first cell in row is empty and there are some other not-empty cells
        If Len(Cells(i, 1)) = 0 And Application.CountBlank(Rows(i)) <> Columns.Count Then
            'we will insert empty row right below that row
            Rows(i + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        End If
    Next i

End Sub

一些信息:

- 它适用于活动表

- 我假设您问题中的第一列是工作表中的 A 列

-code 不检查行中是否有任何 % 符号,但依赖于您传递的其他信息(行中的第一个单元格为空,并且同一行中有一些其他单元格填充了值)

以下图片展示了之前和之后的状态。

在此处输入图像描述 在此处输入图像描述

于 2013-05-26T14:36:08.187 回答