Results 1 to 3 of 3

Inserting rows based on cell

Threaded View

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2011
    Posts
    15

    Inserting rows based on cell

    Can anyone explain to me how this code works? I found it in an article.

    Sub CopyData()
        Dim xRow As Long
        Dim VInSertNum As Variant
        xRow = 1
        Application.ScreenUpdating = False
        Do While (Cells(xRow, "A") <> "")
            VInSertNum = Cells(xRow, "D")
            If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then
               Range(Cells(xRow, "A"), Cells(xRow, "D")).Copy
               Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "D")).Select
               Selection.Insert Shift:=xlDown
               xRow = xRow + VInSertNum - 1
            End If
            xRow = xRow + 1
        Loop
        Application.ScreenUpdating = False
    End Sub
    Does it copy and paste rows from columns A to C based on value in cell D or does it duplicate it another way? I want something like this except I want to insert rows and only copy columns A and B. But if I don't know how to change this code so that column C also shifts down.
    Last edited by hei.so; 01-12-2018 at 03:56 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question Inserting Rows based on cell differences and interpolating in between
    By unknown_member in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2016, 07:21 AM
  2. inserting rows based on cell range not being blanks
    By benoj2005 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2014, 08:33 AM
  3. Inserting Rows Based on Cell Value.
    By feather-chaser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2014, 05:39 AM
  4. [SOLVED] Splitting cell contents based on Comma and inserting new rows below it.
    By SS113 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-22-2013, 09:09 AM
  5. Inserting Rows based on a cell value and populating them.
    By Cleanroomservices in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-22-2012, 11:24 AM
  6. Inserting, Cutting, and Pasting Rows Based on What's in a Cell
    By 4EverLearning in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2010, 04:42 PM
  7. Inserting rows based on cell value
    By iwontbelost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2009, 07:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1