Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2945|回复: 12

[已解决]D列中的数字是几,就在下面增加(几-1)个空白行?

[复制链接]
发表于 2012-5-21 10:31 | 显示全部楼层 |阅读模式
D列中的数字是几,就在下面增加(几-1)个空白行(效果达到 SHEET1式样)。比如说:D3中数字是3,就在下面增加2个空白行(即3-1),D5数字是1,就增加0行(实际就是不增加,即1-1);D6O中数字为4,就增加3个空白行(妈3-1),以此类推。谢谢
最佳答案
2012-5-21 10:39
本帖最后由 zjcat35 于 2012-5-21 11:17 编辑


  1. Sub 插入空行()
  2.     Dim arr, i As Integer, j As Integer
  3.     Application.ScreenUpdating = False
  4.     i = Cells(Rows.Count, 4).End(3).Row
  5.     arr = Range("d4:d" & i)
  6.     For j = i To 5 Step -1
  7. if arr(j-4,1) <> 1 then
  8.         Rows(j).Resize(arr(j - 4, 1)-1).Insert
  9. end if
  10.     Next j
  11.     Application.ScreenUpdating = True
  12. End Sub
复制代码

D列中的数字是几,就在下面增加(几-1)个空白行.rar

9.05 KB, 下载次数: 22

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-5-21 10:39 | 显示全部楼层    本楼为最佳答案   
本帖最后由 zjcat35 于 2012-5-21 11:17 编辑


  1. Sub 插入空行()
  2.     Dim arr, i As Integer, j As Integer
  3.     Application.ScreenUpdating = False
  4.     i = Cells(Rows.Count, 4).End(3).Row
  5.     arr = Range("d4:d" & i)
  6.     For j = i To 5 Step -1
  7. if arr(j-4,1) <> 1 then
  8.         Rows(j).Resize(arr(j - 4, 1)-1).Insert
  9. end if
  10.     Next j
  11.     Application.ScreenUpdating = True
  12. End Sub
复制代码
回复

使用道具 举报

发表于 2012-5-21 10:44 | 显示全部楼层
回复

使用道具 举报

发表于 2012-5-21 11:47 | 显示全部楼层

复制代码

回复

使用道具 举报

发表于 2012-5-21 11:47 | 显示全部楼层
  1. Sub 插入空行()
  2.     Dim arr, i As Integer, j As Integer
  3.     Application.ScreenUpdating = False
  4.     i = Cells(Rows.Count, 4).End(3).Row
  5.     arr = Range("d4:d" & i)
  6.     For j = i To 5 Step -1
  7. If arr(j - 4, 1) <> 1 Then
  8.         Rows(j).Resize(arr(j - 4, 1) - 1).Insert
  9. End If
  10.     Next j
  11.     Application.ScreenUpdating = True
  12. Call tianc
  13. Call heb
  14. End Sub
  15. Sub heb()
  16.   Dim y, mrg1 As Range
  17.     Application.DisplayAlerts = False
  18.      Set mrg1 = [d4]
  19.       For y = 2 To Range("d65536").End(xlUp).Row + 1
  20.         If Cells(y, 4) = Cells(y - 1, 4) Then
  21.           Set mrg = Union(mrg, Cells(y, 4))
  22.         Else
  23.           mrg1.Merge
  24.           Set mrg1 = Cells(y, 4)
  25.         End If
  26.      Next y
  27.     Application.DisplayAlerts = True
  28.    
  29. End Sub
  30. Sub tianc()
  31.   Dim x As Integer
  32.   Dim mrg As Range
  33.      Set mrg = [d4]
  34.     For x = 2 To Range("d65536").End(xlUp).Row - 1
  35.        If Cells(x + 1, 4) = "" Then
  36.          Set mrg = Cells(x, 4)
  37.         Cells(x + 1, 4) = mrg
  38.         
  39.         Else
  40.         
  41.         Set mrg = Cells(x, 4)
  42.        End If
  43.     Next x
  44.    
  45. End Sub

复制代码

回复

使用道具 举报

发表于 2012-5-21 11:49 | 显示全部楼层
Sub 插入空行()
    Dim arr, i As Integer, j As Integer
    Application.ScreenUpdating = False
    i = Cells(Rows.Count, 4).End(3).Row
    arr = Range("d4:d" & i)
    For j = i To 5 Step -1
If arr(j - 4, 1) <> 1 Then
        Rows(j).Resize(arr(j - 4, 1) - 1).Insert
End If
    Next j
    Application.ScreenUpdating = True
Call tianc
Call heb
End Sub
Sub heb()
  Dim y, mrg1 As Range
    Application.DisplayAlerts = False
     Set mrg1 = [d4]
      For y = 2 To Range("d65536").End(xlUp).Row + 1
        If Cells(y, 4) = Cells(y - 1, 4) Then
          Set mrg1 = Union(mrg1, Cells(y, 4))
        Else
          mrg1.Merge
          Set mrg1 = Cells(y, 4)
        End If
     Next y
    Application.DisplayAlerts = True
   
End Sub
Sub tianc()
  Dim x As Integer
  Dim mrg As Range
     Set mrg = [d4]
    For x = 2 To Range("d65536").End(xlUp).Row - 1
       If Cells(x + 1, 4) = "" Then
         Set mrg = Cells(x, 4)
        Cells(x + 1, 4) = mrg
        
        Else
        
        Set mrg = Cells(x, 4)
       End If
    Next x
   
End Sub
回复

使用道具 举报

发表于 2012-5-21 11:50 | 显示全部楼层
运行,插入行。
回复

使用道具 举报

发表于 2012-5-21 11:51 | 显示全部楼层
附件跟上,楼主看一下

楼主看一下.rar

16.06 KB, 下载次数: 9

回复

使用道具 举报

发表于 2012-5-21 11:52 | 显示全部楼层
Sub 插入空行()
    Dim arr, i As Integer, j As Integer
    Application.ScreenUpdating = False
    i = Cells(Rows.Count, 4).End(3).Row
    arr = Range("d4:d" & i)
    For j = i To 5 Step -1
If arr(j - 4, 1) <> 1 Then
        Rows(j).Resize(arr(j - 4, 1) - 1).Insert
End If
    Next j
    Application.ScreenUpdating = True
Call tianc
Call heb
End Sub
Sub heb()
  Dim y, mrg1 As Range
    Application.DisplayAlerts = False
     Set mrg1 = [d4]
      For y = 2 To Range("d65536").End(xlUp).Row + 1
        If Cells(y, 4) = Cells(y - 1, 4) Then
          Set mrg1 = Union(mrg1, Cells(y, 4))
        Else
          mrg1.Merge
          Set mrg1 = Cells(y, 4)
        End If
     Next y
    Application.DisplayAlerts = True
   
End Sub
Sub tianc()
  Dim x As Integer
  Dim mrg As Range
     Set mrg = [d4]
    For x = 2 To Range("d65536").End(xlUp).Row - 1
       If Cells(x + 1, 4) = "" Then
         Set mrg = Cells(x, 4)
        Cells(x + 1, 4) = mrg
        
        Else
        
        Set mrg = Cells(x, 4)
       End If
    Next x
   
End Sub

回复

使用道具 举报

 楼主| 发表于 2012-5-21 14:20 | 显示全部楼层
本帖最后由 小雨饰品 于 2012-5-21 18:50 编辑
zjcat35 发表于 2012-5-21 10:39


感谢大师的帮助。
谢谢谢谢


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-8 11:14 , Processed in 0.286529 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表