+ Reply to Thread
Results 1 to 15 of 15

Copy File Macro - Prevent from seeing "Chunking Along"

Hybrid View

  1. #1
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Copy File Macro - Prevent from seeing "Chunking Along"

    The attached project / copy file macro performs as needed but the user will see as it copies each row. Reminds me of a "chunking along" action.

    Is there someway to keep it from doing that ?

    Requires an empty workbook named "Backup.xlsx"

    Thank you ahead of time !
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Never mind. I answered my own questions. Screenupdating = False.

    It's been a long day staring at the screen.

    Thank you !

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Why are you opening/closing the destination workbook every time you want to copy a row to it?

    Open it once, then run through the source data copying what's required and then close it.

    Try this.
    Sub CopyToBackupFile()
    Dim wbDst As Workbook
    Dim wsDst As Worksheet
    Dim wsSrc As Worksheet
    Dim LastRow As Long, i As Long
    
        Set wsSrc = ActiveSheet
    
        LastRow = wsSrc.Range("A" & Rows.Count).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        Set wbDst = Workbooks.Open(Filename:="C:\Users\My\Desktop\Backup.xlsx")
        Set wsDst = wbDst.Worksheets("Sheet1").Select
    
        For i = 4 To LastRow
    
            If wsSrc.Cells(i, 1) <> "" Then
                wsSrc.Cells(i, 1).Resize(, 16).Copy wsDst.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            End If
    
        Next i
    
        wbDst.Close SaveChanges:=True
    
        Application.ScreenUpdating = True
        
    End Sub
    If posting code please use code tags, see here.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Is there a way to copy and paste the formatting of the cells being copied as well ?

    I've tried (in my code):

    With Sheet1.Cels
            .PasteSpecial Paste:=xlPasteColumnWidths
            .PasteSpecial Paste:=xlPasteFormats
            .PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
    End With

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Norie:

    The syntax hangs on:

     Set wsDst = wbDst.Worksheets("Sheet1").Select
    Error code: Object required.

    Looks like the object is there already ?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Oops, that's a typo.

    Try this, which should copy everything.
    Sub CopyToBackupFile()
    Dim wbDst As Workbook
    Dim wsDst As Worksheet
    Dim wsSrc As Worksheet
    Dim LastRow As Long, i As Long
    
        Set wsSrc = ActiveSheet
    
        LastRow = wsSrc.Range("A" & Rows.Count).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        Set wbDst = Workbooks.Open(Filename:="C:\Users\My\Desktop\Backup.xlsx")
        Set wsDst = wbDst.Worksheets("Sheet1")
    
        For i = 4 To LastRow
    
            If wsSrc.Cells(i, 1) <> "" Then
                wsSrc.Cells(i, 1).Resize(, 16).Copy wsDst.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            End If
    
        Next i
    
        wbDst.Close SaveChanges:=True
    
        Application.ScreenUpdating = True
        
    End Sub

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Sorry .. had a typo :

    With Sheet1.Cells
            .PasteSpecial Paste:=xlPasteColumnWidths
            .PasteSpecial Paste:=xlPasteFormats
            .PasteSpecial Paste:=xlPasteFormulasAndNumberFormats
    End With
    Last edited by Logit; 09-29-2016 at 07:37 PM. Reason: typo

  8. #8
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Logit,

    You realize you are not copying column Q, right ?

    If you're going to copy all rows that aren't blank in column A, have you considered using a filter rather than looping ?

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    NoSparks:

    I'm not familiar with "filter", other than the Menu Bar tool selection. Please explain.

    Re: Leaving out "Q" ... thanks. Another typo.

  10. #10
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    something along the lines of this will do the copy in one shot

    Sub CopyToBackupFile()
    
        Dim srcSht As Worksheet
        Dim destWB As Workbook
        Dim FiltRng As Range
        Dim lr As Long
    
    Application.ScreenUpdating = False
    
    Set srcSht = ActiveSheet
    lr = srcSht.Cells(Rows.Count, "A").End(xlUp).Row
    Set FiltRng = srcSht.Range("A3:P" & lr)
    
    Set destWB = Workbooks.Open Filename:="C:\Users\My\Desktop\Backup.xlsx"
    'Set destWB = Workbooks.Open(Filename:=ThisWorkbook.Path & "\" & "Backup.xlsx")
    
    With FiltRng
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>"
        .Offset(1).Copy
    End With
    
    With destWB.Sheets("Sheet1")
        .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
        .Cells(1, 1).Select
    End With
    
    destWB.Close SaveChanges:=True
    
    FiltRng.AutoFilter
    
    Application.ScreenUpdating = True
    
    End Sub

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    NoSparks

    Works great.

    Is there a means of maintaining the same format of the cells as they are copied over to the backup workbook ?

    See #7 above for my previous feeble attempt.

  12. #12
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    .PasteSpecial xlPasteAll should have looked after that.

    For me it copied different fonts and cell colors.

    Within the macro, put your cursor somewhere in PasteSpecial and hit F1,
    On the help page that comes up click on xlPasteType.

  13. #13
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    This worked ... do you see anything that should be changed ?

    With destWB.Sheets("Sheet1")
        .cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteColumnWidths
        .cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteFormats
        .cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteFormulasAndNumberFormats 'PasteSpecial xlPasteAll
        .cells(1, 1).Select
    End With

  14. #14
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    That looks OK to me but I think only experimentation will tell you for sure.

    After a little further testing I did find that xlPasteAll didn't actually paste all, just most things.
    Needed the xlPasteColumnWidths to be implemented first, as you no doubt also discovered.

    The cells(1,1).select is just used so as to not leave the sheet with the entire copy area selected (I hate opening up a sheet to find a massive range selected).

  15. #15
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,429

    Re: Copy File Macro - Prevent from seeing "Chunking Along"

    Thanks friend. Sent you a private message.

+ 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. Short "Basic" Macro to copy and paste formulas "N" times.
    By gradyhawks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2014, 02:34 PM
  2. Need Macro code to attach the words "FILE COPY" to second page only when printed?
    By ElmerFud in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2014, 12:03 PM
  3. Need Macro code to attach the words "FILE COPY" to second page only when printed?
    By ElmerFud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-04-2014, 10:21 AM
  4. [SOLVED] VBA macro to copy ActiveSheet plus sheet named "Filters" to a separate file
    By CherylC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2014, 08:19 PM
  5. [SOLVED] Copy contents from "Child" file to a "Master"
    By pipoliveira in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 02-13-2014, 09:44 AM
  6. [SOLVED] Prevent "copy to next empty row" from copying the Web Query link
    By 4evra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2013, 09:10 AM
  7. How can i copy value from "HTMLText"(EMBED("Forms.HTML:Text","")),using Macro
    By andrewyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2010, 12:47 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