Add 3 rows to existing vba code

∥☆過路亽.° 提交于 2020-01-06 13:58:53

问题


Below is vba code that I am using now. Edit details at the bottom.

Sub AddBlankRows()
'
Dim iRow As Integer
Range("a1").Select
'
iRow = 1
'
Do
'
If Cells(iRow + 1, 1) <> Cells(iRow, 1) Then
    Cells(iRow + 1, 1).EntireRow.Insert shift:=xlDown
    iRow = iRow + 2
Else
    iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, 2).Text = ""
'
End Sub

The above vba code I found (googling) in one of Stackoverflows questions that someone has asked, and it worked for my purpose. However I cannot locate it to give information as to which question it arose from.

I am now using it and works great. However I need more rows added. So I have to manually insert rows as I need them. I would like to make the vba code do it for me. Instead of adding 1 row after each grouped cell. I need 3 rows added. Could somebody help me edit the above macro to allow it to give me 3 rows rather than 1 row.

This is my first post and thanking everybody in advance. GraceSarah


回答1:


This would be the least invasive way to modify your existing formula to add 2 more rows

Sub AddBlankRows()
'
Dim iRow As Integer
Dim x as Integer
Range("a1").Select
'
iRow = 1
'
Do
'
If Cells(iRow + 1, 1) <> Cells(iRow, 1) Then
    For x = 1 To 3
        Cells(iRow + 1, 1).EntireRow.Insert shift:=xlDown
    Next x
    iRow = iRow + 4
Else
    iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, 2).Text = ""
'
End Sub


来源:https://stackoverflow.com/questions/19982706/add-3-rows-to-existing-vba-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!