Results 1 to 7 of 7

Insert rows, repetative copy and paste - slow macro

Threaded View

pnnaik Insert rows, repetative copy... 02-25-2016, 07:46 AM
sourabhg98 Re: Insert rows, repetative... 02-25-2016, 08:10 AM
pnnaik Re: Insert rows, repetative... 02-25-2016, 08:29 AM
sourabhg98 Re: Insert rows, repetative... 02-25-2016, 08:41 AM
pnnaik Re: Insert rows, repetative... 02-25-2016, 11:34 AM
sourabhg98 Re: Insert rows, repetative... 02-25-2016, 11:56 AM
pnnaik Re: Insert rows, repetative... 02-25-2016, 12:21 PM
  1. #1
    Registered User
    Join Date
    01-17-2015
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    85

    Insert rows, repetative copy and paste - slow macro

    Dear All,

    I have written code with the help of some of the previous post on this site.

    I have data sheet. I am to arrange this data sheet to upload it.


    To arrange data sheet I am to insert some numbers of rows after certain number of rows.

    After that some copy operation is there.

    Code run as desired by me but is SLOW.

    Kindly suggest modification to run it faster. Kindly note I do not know much about VBA coding.

    Code

    Sub Test()
    Dim intCOLUMN_TO_WORK_IN As Integer
    Dim lngROW_TO_STOP_AT As Long
    Dim LRow As Long
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim i As Long
    Dim j As Long
    Dim Width As Double
    Dim Height As Double
    Dim Thickness As Double
    Dim rng As Range
    
    Width = InputBox("Enter Width: ")
    Height = InputBox("Enter Height: ")
    Thickness = InputBox("Enter Thickness: ")
    
    Set ws1 = Sheets("DATA")
    Set ws2 = Sheets("UPLOAD")
    Set rng = ws1.Range(Cells(2, 1), Cells(2, 10).End(xlDown))
    
      
    rng.Sort Key1:=Cells(2, 2), Order1:=xlAscending, DataOption1:=xlSortNormal
    
    On Error GoTo Handler:
    Application.ScreenUpdating = False
    
    Set ws1 = ActiveSheet
    intCOLUMN_TO_WORK_IN = 2 'A
    lngROW_TO_STOP_AT = 5 'header row, if needed
    
    With ws1
        LRow = .Cells(Rows.Count, 2).End(xlUp).Row
        For i = LRow To lngROW_TO_STOP_AT Step -4
            For j = 1 To 7
                .Cells(i + 1, intCOLUMN_TO_WORK_IN).EntireRow.Insert shift:=xlDown
            Next j
        Next i
      LRow = .Cells(Rows.Count, 2).End(xlUp).Row
      
      For i = 1 To LRow Step 11
        .Range("a1:j1").Copy .Range("a" & i)
        .Range("k" & i).Value = "Width"
        .Range("L" & i).Value = "Height"
        .Range("M" & i).Value = "Thickness"
        .Range("K2:K5").Value = Width
        .Range("L2:L5").Value = Height
        .Range("M2:M5").Value = Thickness
      Next i
    
      For i = 13 To LRow Step 11
        .Range("a2:a5").Copy .Range("a" & i)
        .Range("K2:M5").Copy .Range("K" & i)
      Next i
        .Range("A1:M" & LRow).Copy: ws2.Range("B10").PasteSpecial xlPasteValues
    End With
    My_Exit_Sub:
    Application.ScreenUpdating = True
    Exit Sub
    Handler:
    MsgBox "Error: " & Err.Number & ": " & Err.Description
    Resume My_Exit_Sub:
    End Sub

    Regards,

    PN
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 10-05-2014, 12:28 PM
  2. [SOLVED] Copy and Paste using macro very slow is this code correctly done? Need help with a edit
    By Mr_Bill in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2014, 07:39 PM
  3. Code to insert rows and copy data is too slow
    By muddbog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2014, 10:52 AM
  4. Excel insert macro is hyper slow after 3k rows
    By aperri in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2012, 09:55 PM
  5. Excel Macro to insert two rows based on condition and copy and paste multiple cells
    By mannabhalo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2012, 12:56 PM
  6. [SOLVED] Copy, paste and insert new rows into new sheets
    By nanas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2012, 10:35 PM
  7. Copy/paste macro is running slow
    By Kaplan275 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2012, 08:28 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