【原创】VBA学习笔记(2)--实例,VBA删除表中的空行

Sub 宏1循环内删列()
'数据不规范,有的空行是4,有的是6,有的是1就不好处理了

    For i = 15 To 100 Step 2
         Rows(i).Delete Shift:=xlUp
         Rows(i).Delete Shift:=xlUp
         Rows(i).Delete Shift:=xlUp
         Rows(i).Delete Shift:=xlUp
    Next
End Sub

Sub 宏2两层循环()
     For j = 0 To 2
    'For i = i To i + 3
        For i = 3 + 6 * j To 6 + 6 * j
        thissheet.Row(i).Select
        'thissheet.Row(i + 1).Select
        'thissheet.Row(i + 2).Select
        'thissheet.Row(i + 3).Select
         thissheet.Row(i).Color = red
         Next
    Next
    i = i + 2
    
    'then
    Selection.Delete Shift:=xlUp
End Sub


Sub 宏3单层循环()
'http://club.excelhome.net/thread-879382-1-1.html?jdfwkey=wt4m13
'问题是只选中了最后的行
    For i = 1 To 5
        Rows((12 + 6 * i - 3) & ":" & (12 + 6 * i)).Select
        'Rows(12 + 6 * i - 1).Select
        'Rows(12 + 6 * i - 2).Select
        'Rows(12 + 6 * i - 3).Select
        Selection.Interior.ColorIndex = 3
        Application.Wait Now() + CDate("00:00:01")
    Next
    Selection.Delete Shift:=xlUp
End Sub


Sub 宏4()

    For i = 2 To 10
        ActiveSheet.Rows(i).Select
        ActiveSheet.Rows(i + 1).Select
        ActiveSheet.Rows(i + 2).Select
        ActiveSheet.Rows(i + 3).Select
ActiveSheet.Rows(i).Interior.ColorIndex = 3
         
    Next
    i = i + 2
    
    'then
    'Selection.Delete Shift:=xlUp
End Sub

上述可能方法思路都对,但暂时写的语法都不对,还得研究下面2个

https://zhidao.baidu.com/question/519023339630639085.html

http://club.excelhome.net/thread-879382-1-1.html?jdfwkey=wt4m13

猜你喜欢

转载自blog.csdn.net/xuemanqianshan/article/details/81772066