Advertisement
Guest User

Untitled

a guest
Aug 6th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub CopyData()
  2.  
  3.     'Declare all variables
  4.    Dim bInsertParent As Variant
  5.     Dim iLastRow As Integer
  6.     Dim iTotalRows As Integer
  7.  
  8.     'Get index for the last row
  9.    iTotalRows = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
  10.  
  11.     'Start inserting stuff after the last populated row
  12.    iLastRow = iTotalRows + 1
  13.  
  14.     Application.ScreenUpdating = False
  15.  
  16.     'Start at the second row
  17.    For iRowIndex = 2 To iTotalRows
  18.         'Fetch insert parent flag
  19.        bInsertParent = Cells(iRowIndex, "X")
  20.  
  21.         'If column X for iRowIndex equals 2 and is numeric
  22.        If ((bInsertParent = 2) And IsNumeric(bInsertParent)) Then
  23.  
  24.             'Copy and paste special macro calls
  25.            Rows(iRowIndex).Copy
  26.             Rows(iLastRow).PasteSpecial xlPasteAll
  27.            
  28.             'Last row is now the next available row
  29.            iLastRow = iLastRow + 1
  30.         End If
  31.     Next iRowIndex
  32.  
  33.  
  34.     Application.ScreenUpdating = True
  35. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement