Guest User

Untitled

a guest
Oct 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Значение
  2. пустая ячейка
  3. значение
  4. пустая ячейка
  5.  
  6. Sub InsertRows()
  7. Dim a()
  8. Dim rRng As Range
  9. Dim lStart As Long, lRw As Long, lClmn As Long
  10. Dim i As Long, n As Byte
  11. Set rRng = Application.InputBox("Выбрать диапазон", , Type:=8)
  12. lClmn = rRng.Column
  13. lStart = rRng.Row: lRw = rRng.Rows.Count + rRng.Row - 1
  14.  
  15. a = Cells(1, lClmn).Resize(lRw + 2, 1).Value
  16. Application.ScreenUpdating = False
  17.  
  18. For i = lRw To lStart Step -1
  19. If a(i, 1) <> Empty Then
  20. n = 0
  21.  
  22. If a(i + 1, 1) <> Empty Then
  23. n = 2
  24. Else
  25. If a(i + 2, 1) <> Empty Then n = 1
  26. End If
  27.  
  28. If n > 0 Then Cells(i + 1, lClmn).Resize(n, 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
  29. End If
  30. Next i
  31.  
  32. Application.ScreenUpdating = True
  33. Set rRng = Nothing
  34. End Sub
Add Comment
Please, Sign In to add comment