+ Reply to Thread
Results 1 to 5 of 5

Slight edit needed - grouping x

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Slight edit needed - grouping x

    I am using the code bellow to copy across data contained in rows in columns e,f & g only if there is data in column f for that row:

    It works but it currently copies each row in turn, which just slows the process down a bit. So I was hoping to group all the rows together so they copy across in one go but I am unsure how to do this...any ideas?

    Sub OpenRecordForm_Discrepancies()
    Dim i As Long, x As Range
        With Sheets("Discrepancies")
            For i = 6 To .Range("g" & Rows.Count).End(xlUp).Row
            Set x = .Cells(i, "e").Resize(, 3)
            If .Cells(i, "f").Value = "" Then
                    Exit Sub
                Else: x.Copy
                Sheets("Upload Sheet").Range("a" & Rows.Count).End(xlUp)(2).PasteSpecial _
                Paste:=xlPasteValues
            End If
        Next
    End With
    Thanks in advance,

    Strud

  2. #2
    Registered User
    Join Date
    04-30-2013
    Location
    Cranfield
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: Slight edit needed - grouping x

    One way to speed this up would be to modify the code like this:

    Sub OpenRecordForm_Discrepancies()
    Application.ScreenUpdating = False
    Dim i As Long, x As Range
        With Sheets("Discrepancies")
            For i = 6 To .Range("g" & Rows.Count).End(xlUp).Row
            Set x = .Cells(i, "e").Resize(, 3)
            If .Cells(i, "f").Value = "" Then
                    Exit Sub
                Else: x.Copy
                Sheets("Upload Sheet").Range("a" & Rows.Count).End(xlUp)(2).PasteSpecial _
                Paste:=xlPasteValues
            End If
        Next
    End With
    Application.ScreenUpdating = True

  3. #3
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Slight edit needed - grouping x

    awesome thanks!

    How does that work if you wouldn't mind explaining quickly?

  4. #4
    Forum Contributor
    Join Date
    04-19-2013
    Location
    Yorkshire, England
    MS-Off Ver
    Excel 2010
    Posts
    297

    Re: Slight edit needed - grouping x

    Just looked it up, so got it ....cheers anyway for the help!

  5. #5
    Registered User
    Join Date
    04-30-2013
    Location
    Cranfield
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: Slight edit needed - grouping x

    No problem
    I use Application.ScreenUpdating in most of my macros as I rarely actually need to see what is going on and it really speeds things up!

+ 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