+ Reply to Thread
Results 1 to 6 of 6

Stop Inserting Entire Row, Only Insert Range

Hybrid View

NaNaBoo Stop Inserting Entire Row,... 03-24-2009, 10:28 AM
shg Re: Stop Inserting Entire... 03-24-2009, 10:47 AM
NaNaBoo Re: Stop Inserting Entire... 03-24-2009, 11:04 AM
NaNaBoo Re: Stop Inserting Entire... 03-24-2009, 03:15 PM
shg Re: Stop Inserting Entire... 03-24-2009, 07:18 PM
NaNaBoo Re: Stop Inserting Entire... 03-25-2009, 10:27 PM
  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Stop Inserting Entire Row, Only Insert Range

    This is a very simply problem that I do not know how to fix.

    Right now, the code below is inserting an entire row when it pastes the values in I only want the values to be inserted in Range (A:AJ).

    The code seems to work great, that is the only problem. Please help.

    I gratefully appreciated it.

    Sub Macro1()
    Set compro = Sheets("Sheet1")
    cpqr = 1
    
    
    For Each sh In Worksheets          'Cycle through all the sheets in the workbook
    
            'Determine whether this is a project worksheet
        If sh.Name = "Product1" Or sh.Name = "Product2" Then
            pr = 1                                                              'Keep track of which row on the project worksheet
            With sh
                Do Until pr > .Cells(1, 1).SpecialCells(xlLastCell).Row   'Stop when you get to the last row
                
            'Determine which quarter to paste into
                    If .Cells(pr, 1) = "Current" Or .Cells(pr, 1) = "90 Days" Or .Cells(pr, 1) = "180 Days" Then
                        qtr = .Cells(pr, 1)
                        pr = pr + 1
        
            'Find the next empty row in the right quarter on the combined sheet
                        cpqr = compro.Cells.Find(qtr, compro.Range(compro.Cells(cpqr, 1), compro.Cells(cpqr, 1))).Row + 2
                        Do While compro.Cells(cpqr, 1) <> ""
                            cpqr = cpqr + 1
                        Loop
                    End If
                    
            'If this row on the project sheet has data, copy it to the combined sheet
                    If .Cells(pr, 1) <> "" Then
                        compro.Range(compro.Cells(cpqr, 1), compro.Cells(cpqr, 1)).EntireRow.Insert
                        .Range(.Cells(pr, 3), .Cells(pr, 35)).Copy
                        compro.Range(compro.Cells(cpqr, 3), compro.Cells(cpqr, 35)).PasteSpecial Paste:=xlPasteValues
                        cpqr = cpqr + 1
                    End If
                    pr = pr + 1
                Loop
            End With
        End If
    Next
    
    End Sub
    Last edited by NaNaBoo; 03-26-2009 at 02:42 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Stop Inserting Entire Row, Only Insert Range

    At a glance (untested), try
    compro.Range(compro.Cells(cpqr, 1), compro.Cells(cpqr, 1)).Insert Shift:=xlShiftDown
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Stop Inserting Entire Row, Only Insert Range

    Shg,

    Thanks that worked.
    Last edited by NaNaBoo; 03-24-2009 at 03:15 PM.

  4. #4
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Stop Inserting Entire Row, Only Insert Range

    Another problem was caused by the new change to the code.
    It is copying over the first copy of values.

    It copy the values from "Products1" and once that is compled, it then copies the values from "Product2" over the "Product1" values.

    Any ideas as to why?

    Also, is it possible to have the cells copy and insert starting from columns C instead of column A
    Last edited by NaNaBoo; 03-26-2009 at 02:39 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Stop Inserting Entire Row, Only Insert Range

    No idea without seeing the workbook, no.

  6. #6
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Stop Inserting Entire Row, Only Insert Range

    Here is the workbook.
    Attached Files Attached Files
    Last edited by NaNaBoo; 03-26-2009 at 02:41 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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