+ Reply to Thread
Results 1 to 6 of 6

Copy/Drag Down for Data range's running extremely slow.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Copy/Drag Down for Data range's running extremely slow.

    Hey, I'm trying to get this macro below working faster but it's going incredibly slow for a reason I don't know...

        Dim rngName As Range: Set rngName = Range("A6:A15000").Find("Name")
        If rngName Is Nothing Then
            MsgBox "No cells in column A that contain ""Name"""
            Exit Sub
        End If
        Dim rngPrior As Range: Set rngPrior = rngName
        
        While Not rngName Is Nothing
            If rngName.Row < rngPrior.Row Then Exit Sub
            rngName.Offset(1, 130).Copy rngName.Offset(1, 130).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 131).Copy rngName.Offset(1, 131).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 132).Copy rngName.Offset(1, 132).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 133).Copy rngName.Offset(1, 133).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 134).Copy rngName.Offset(1, 134).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 135).Copy rngName.Offset(1, 135).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 141).Copy rngName.Offset(1, 141).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 142).Copy rngName.Offset(1, 142).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 143).Copy rngName.Offset(1, 143).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 144).Copy rngName.Offset(1, 144).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 145).Copy rngName.Offset(1, 145).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 160).Copy rngName.Offset(1, 160).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 161).Copy rngName.Offset(1, 161).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 162).Copy rngName.Offset(1, 162).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 163).Copy rngName.Offset(1, 163).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 164).Copy rngName.Offset(1, 164).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 165).Copy rngName.Offset(1, 165).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 161).Copy rngName.Offset(1, 171).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 162).Copy rngName.Offset(1, 172).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 173).Copy rngName.Offset(1, 173).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 174).Copy rngName.Offset(1, 174).Resize(rngName.CurrentRegion.Rows.Count - 3)
            rngName.Offset(1, 175).Copy rngName.Offset(1, 175).Resize(rngName.CurrentRegion.Rows.Count - 3)
            Set rngPrior = rngName
            Set rngName = Range("A6:A15000").Find("Name", rngName)
        Wend
    Last edited by Hyflex; 12-22-2011 at 09:37 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Copy/Drag Down for Data range's running extremely slow.

    Hi Hyflex

    Gotta be a better way , what are you doing?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Copy/Drag Down for Data range's running extremely slow.

    I've attached an example of a smaller version of what it does...
    Attached Files Attached Files

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Copy/Drag Down for Data range's running extremely slow.

    Hi Hyflex
    Maybe something like...
    Sub Example()
        
        Dim rngName As Range: Set rngName = Range("A6:A15000").Find("Name")
        If rngName Is Nothing Then
            MsgBox "No cells in column A that contain ""Name"""
            Exit Sub
        End If
        Dim rngPrior As Range: Set rngPrior = rngName
        
        While Not rngName Is Nothing
            If rngName.Row < rngPrior.Row Then Exit Sub
           Range(rngName.Offset(1, 7), rngName.Offset(1, 10)).Copy rngName.Offset(1, 7).Resize(rngName.CurrentRegion.Rows.Count - 3)
          '  rngName.Offset(1, 8).Copy rngName.Offset(1, 8).Resize(rngName.CurrentRegion.Rows.Count - 3)
           ' rngName.Offset(1, 9).Copy rngName.Offset(1, 9).Resize(rngName.CurrentRegion.Rows.Count - 3)
           ' rngName.Offset(1, 10).Copy rngName.Offset(1, 10).Resize(rngName.CurrentRegion.Rows.Count - 3)
            Set rngPrior = rngName
            Set rngName = Range("A6:A15000").Find("Name", rngName)
        Wend
        
    End Sub

  5. #5
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Copy/Drag Down for Data range's running extremely slow.

    Oh wow silly me, yeah that works so much faster.
    It was taking 5-10mins to do the things I wanted now this one takes under 2mins

    Thank you very much

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Copy/Drag Down for Data range's running extremely slow.

    how much fasteris this?

    Option Explicit
    Sub Example()
        Dim rngName As Range
        Dim rngPrior As Range
        
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        
        Set rngName = Range("A6:A15000").Find("Name")
        
        If rngName Is Nothing Then
            MsgBox "No cells in column A that contain ""Name"""
            Exit Sub
        End If
        
        Set rngPrior = rngName
        
        While Not rngName Is Nothing
            
            If rngName.Row < rngPrior.Row Then Exit Sub
            
            With Sheet1.Range(rngName.Offset(1, 7), rngName.Offset(1, 10))
                .Resize(rngName.CurrentRegion.Rows.Count - 3).Value = .Value
            End With
            
            Set rngPrior = rngName
            Set rngName = Range("A6:A15000").Find("Name", rngName)
        
        Wend
        
        Set rngPrior = Nothing
        Set rngName = Nothing
        
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationAutomatic
    
    End Sub

+ 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