+ Reply to Thread
Results 1 to 14 of 14

Copying Down Formulas

Hybrid View

frog0234 Copying Down Formulas 02-08-2013, 11:28 AM
RHCPgergo Re: Copying Down Formulas 02-08-2013, 11:53 AM
Pepe Le Mokko Re: Copying Down Formulas 02-08-2013, 11:57 AM
frog0234 Re: Copying Down Formulas 02-08-2013, 02:12 PM
frog0234 Re: Copying Down Formulas 02-08-2013, 03:59 PM
frog0234 Re: Copying Down Formulas 02-11-2013, 10:43 AM
RHCPgergo Re: Copying Down Formulas 02-11-2013, 11:05 AM
frog0234 Re: Copying Down Formulas 02-11-2013, 12:36 PM
RHCPgergo Re: Copying Down Formulas 02-11-2013, 05:05 PM
jleonard5106 Re: Copying Down Formulas 02-11-2013, 06:16 PM
frog0234 Re: Copying Down Formulas 02-12-2013, 03:34 PM
jleonard5106 Re: Copying Down Formulas 02-12-2013, 10:52 PM
jleonard5106 Re: Copying Down Formulas 02-12-2013, 11:53 PM
frog0234 Re: Copying Down Formulas 02-13-2013, 02:16 PM
  1. #1
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Copying Down Formulas

    I am using Excel 2007 and have a spread sheet of 800 columns and 163,000 rows. In each cell of the first row are equations similar to this: =VLOOKUP(F4,Sheet2!$A$1:$ADT$571,H$3)-VLOOKUP(G4,Sheet2!$A$1:$ADT$571,H$3)

    I am trying to copy down this row to row 163,000 and am only able to get to around row 15,000 before I get the message that I have run out of system resources. I have tried turning off auto calculations in the cells. What else can I do to populate the cells with the formulas?

    Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Copying Down Formulas

    Hey,
    first select the range where you want to formula to be pasted, then run this macro.
    I assumed that your selection starts in row 4. If not, tell me and I will alter the code.
    Sub CopyFormula()
    'I assumed that your selection starts in row 4
    Dim Rng As Range
    Dim i As Long
    Application.ScreenUpdating = False
    For Each Rng In Selection
        i = Rng.Row
        Rng.Value = "=VLOOKUP(F" & i & _
        ",Sheet2!$A$1:$ADT$571,H$3)-VLOOKUP(G " & i & _
        ",Sheet2!$A$1:$ADT$571,H$3)"
    Next Rng
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,636

    Re: Copying Down Formulas

    If you could post a small sample of your sheet so we can see what you are trying to do, it would help us a lot.
    I also thing an INDEX/MATCH combination needs less resources

  4. #4
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    Here is the spreadsheet I am working with. I tried the VBA code and am getting an error.

    Any other ideas?

  5. #5
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    Here is the file. I have removed alot of the data from Sheets 1 & 2 to allow for upload. But again, I am trying to drag down the first row of formulas about 163,000 rows. The data table in Sheet 2 has 571 rows of 800 columns.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    Any thoughts on this?

  7. #7
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Copying Down Formulas

    Hi again,

    how about this one?
    http://spreadsheets.about.com/od/tip...30filldown.htm

    Applied to your case:
    1. highlight your first row of data (from column C to the end)
    2. press F5 (brings up the "Go to" dialog box)
    3. type in the bottom right cell address of the range where you want to apply the formula (should be something like this: ADT163000)
    4. click OK while holding shift (now all that huge range should be highlighted)
    5. press Ctrl + D
    6. formula should be applied everywhere.

    Tell me if it works please.

  8. #8
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    Neat trick, but it doesn't work for this situation. I first get the warning notice of "large data operation", after I click ok I get "Excel cannot complete this task with available resources. Choose less data or close other applications"

    Other ideas?

  9. #9
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Copying Down Formulas

    Wow.

    How about applying it in smaller chunks? Like for every ten thousand row?
    Also, once you have the correct data in the cells, you can use Copy-->Paste Special-->Values, so formulas disappear. Makes the file size smaller.

  10. #10
    Registered User
    Join Date
    01-14-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Copying Down Formulas

    Try this code. i have also attached the file.

    I created a copy of sheet 1 and named it test.

    Sub CopyFormula()
    
    Dim FinalRow As Long
    Dim FinalCol As Long
    
    Dim Ws1 As Worksheet
        
        Set Ws1 = ThisWorkbook.Worksheets("Test")
    
        FinalRow = Ws1.Cells(Rows.Count, 1).End(xlUp).Row - 4
        FinalCol = Ws1.Cells(4, Columns.Count).End(xlToLeft).Column - 2
        
        Ws1.Cells(5, 3).Resize(FinalRow, FinalCol).FormulaR1C1 = "=VLOOKUP(RC1,Sheet2!R1C1:R571C800,R4C)-VLOOKUP(RC2,Sheet2!R1C1:R571C800,R4C)"
        
    End Sub
    Attached Files Attached Files
    Last edited by jleonard5106; 02-11-2013 at 06:17 PM. Reason: File did not Upload

  11. #11
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    The VBA code works to about row 7000 and then I get an error stating that there are no more system resources available to continue.

    Other ideas?

  12. #12
    Registered User
    Join Date
    01-14-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Copying Down Formulas

    I am still working on it.

    are the formulas important or just number?

  13. #13
    Registered User
    Join Date
    01-14-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Copying Down Formulas

    Try this Code

    Took away the vlookups and just used simple subtractions

    Sub CopyFormula()
    
    
    Dim WsR As Worksheet 'worksheet report
    Dim WsD As Worksheet 'worksheet data
    
    'Report Sheet
    Dim FinalRowWsR As Long
    Dim FinalColWsR As Long
    'Data Sheet
    Dim FinalRowWsD As Long
    Dim FinalColWsD As Long
    
    Dim MyArray1() As Variant
    Dim MyArray2() As Variant
    
    Dim Dta As Long
    Dim Crit As Long
    Dim c As Long
    
    Dim Crit1 As String
    Dim Crit2 As String
    
    Dim Crit1A As Long
    Dim Crit2A As Long
    
    Set WsR = ThisWorkbook.Worksheets("Report")
    Set WsD = ThisWorkbook.Worksheets("Data")
    
    Application.ScreenUpdating = False
    
    FinalRowWsD = WsD.Cells(Rows.Count, 1).End(xlUp).Row
    FinalColWsD = WsD.Cells(1, Columns.Count).End(xlToLeft).Column
    FinalRowWsR = WsR.Cells(Rows.Count, 1).End(xlUp).Row
    FinalColWsR = WsR.Cells(4, Columns.Count).End(xlToLeft).Column - 1
    
    'loop to find the criteria row on wsd
    For Crit = 5 To FinalRowWsR
        Crit1 = WsR.Cells(Crit, 1).Value
        Crit2 = WsR.Cells(Crit, 2).Value
        
        Crit1A = 0
        Crit2A = 0
        
        For Dta = 1 To FinalRowWsD
            Select Case WsD.Cells(Dta, 1).Value
                Case Crit1
                    Crit1A = WsD.Cells(Dta, 1).Row
                Case Crit2
                    Crit2A = WsD.Cells(Dta, 1).Row
            End Select
            
            If Crit1A And Crit2A <> 0 Then Exit For
            
        Next Dta
        'formula
        ReDim MyArray1(1 To FinalColWsD)
        ReDim MyArray2(1 To FinalColWsD)
        
        MyArray1() = WsD.Range(WsD.Cells(Crit1A, 2), WsD.Cells(Crit1A, FinalColWsD))
        MyArray2() = WsD.Range(WsD.Cells(Crit2A, 2), WsD.Cells(Crit2A, FinalColWsD))
        
        For c = 3 To FinalColWsD + 1
            WsR.Cells(Crit, c).Value = MyArray1(1, c - 2) - MyArray2(1, c - 2)
        Next c
        
        Application.StatusBar = "On Record " & Crit
        
    Next Crit
    
    Application.StatusBar = True
    Application.ScreenUpdating = True
    End Sub

  14. #14
    Registered User
    Join Date
    02-01-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copying Down Formulas

    Wow, I really appreciate your work. I don't use message boards often, but it is nice to see people so willing to help others especially with the complexity to your VBA code. I started to run it, but it is taking a long time (which is ok), I will have to run it when I can walk away from the computer for a bit. I will let you know the final outcome. Thanks again. I will follow up soon.

+ 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