+ Reply to Thread
Results 1 to 3 of 3

cycle through records on one sheet and write 6 rows per record on another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-11-2014
    Posts
    2

    cycle through records on one sheet and write 6 rows per record on another sheet

    hello, i need some help on speeding up the process of cycling through about 270 records(rows) on one sheet and adding 6 rows per record on another sheet, right it's taking about 20 minutes. i should also say that each of those 6 lines has different values for the 4 columns that i fill, i also need to copy the formulas and data validation formulas to all the cells within that range

    is it possible to "write" the 270*6 rows on the ram and them dumping all the rows at once on the sheet?
    how can i speed this up?

    my currrent code is as follows

    Set rngIPID = Sheets("1").Range("A12:A" & sLastLine)
    
    Sheets("2").Select
    'percorre as linhas da coluna de ipid
    For Each rngLine In rngIPID
    
    
    If rngLine .Value <> "" Then
                               
                        sLastLineSheet2 = Sheets("2").Cells(Cells.Rows.Count, "A").End(xlUp).Row
                        
    
                        ' i copy the range and insert it down because i want to keep the formulas from a "template" row
    
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
                        
                                            
                        sLastLineSheet2 = sLastLineSheet2 + 1
                        
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_TEMPO
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_INICIO_VAZIO
                        
                        Cells(sLastLineSheet2 , "A").Interior.Color = RGB(253, 253, 0)
                        Cells(sLastLineSheet2 , "B").Interior.Color = RGB(0, 176, 240)
                        Cells(sLastLineSheet2 , "C").Interior.Color = RGB(0, 176, 240)
                        Cells(sLastLineSheet2 , "D").Interior.Color = RGB(0, 176, 240)
                        Cells(sLastLineSheet2 , "E").Interior.Color = RGB(0, 176, 240)
                        Cells(sLastLineSheet2 , "F").Interior.Color = RGB(0, 176, 80)
                        Cells(sLastLineSheet2 , "G").Interior.Color = RGB(0, 176, 80)
                        Cells(sLastLineSheet2 , "H").Interior.Color = RGB(0, 176, 80)
                        
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
                        
                        sLastLineSheet2 = sLastLineSheet2 + 1
    
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_TEMPO
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_PERCURSO
                        
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
    
                        sLastLineSheet2 = sLastLineSheet2 + 1
    
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_TEMPO
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_FIM_VAZIO
                        
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
                        
                        sLastLineSheet2 = sLastLineSheet2 + 1
    
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_DISTANCIA
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_INICIO_VAZIO
                        
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
    
                        sLastLineSheet2 = sLastLineSheet2 + 1
    
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_DISTANCIA
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_PERCURSO
                        
                        Range("A" & sLastLineSheet2 & ":" & "L" & sLastLineSheet2 ).Select
                        Selection.Copy
                        Selection.Insert Shift:=xlDown
                        
                        sLastLineSheet2 = sLastLineSheet2 + 1
    
                        Cells(sLastLineSheet2 , "A").Value = rngLine .Value
                        Cells(sLastLineSheet2 , "B").Value = CONCELHO
                        Cells(sLastLineSheet2 , "C").Value = TIPO_MEDICAO_DISTANCIA
                        Cells(sLastLineSheet2 , "D").Value = CLASSE_FIM_VAZIO
                        
    
            End If
    
    Next

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: cycle through records on one sheet and write 6 rows per record on another sheet

    It might be that the slowness is caused by your formulae recalculating.

    If so you might try

    Application.Calculation = xlCalculationManual
    towards the start of the code and

    Application.Calculation  = xlCalculationAutomatic
    at the end
    Martin

  3. #3
    Registered User
    Join Date
    06-11-2014
    Posts
    2

    Re: cycle through records on one sheet and write 6 rows per record on another sheet

    thank you very much, right now it's taking about 2 minutes so your suggestion worked very well, however 2 minutes is still too long. i've been told that we might have thousands of records on sheet1 so it will take too long, can i use an array or something like that to "paste" all the cells at once?

    EDIT: i think i've figured it out, i just assign the values (which is very fast) and then add the formulas and such
    Last edited by Phaster; 06-12-2014 at 05:14 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 06-11-2014, 11:14 AM
  2. Cycle throuhg rows on a sheet
    By Sparkplug90 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-11-2014, 07:25 PM
  3. Replies: 2
    Last Post: 12-20-2013, 01:09 PM
  4. VBA Read, write records to one sheet. Query
    By dan007004 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2011, 03:03 AM
  5. Filter records, paste into a different sheet, delete rows from original sheet.
    By gloworm1973 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2009, 05:24 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