+ Reply to Thread
Results 1 to 11 of 11

Thread: Fill cells with formula, one by one, AutoFill?

  1. #1
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Fill cells with formula, one by one, AutoFill?

    Hello,
    can anyone tell me how I can fill out the cells of a column with a formula (please bear with me if I make any mistakes, English is not my native language. Thanks)

    I have a table with thousands of data sets. The last 3 columns X Y Z are filled with formulas.

    The problem is that every recalculation requires a few seconds. So, my idea was to write the formula only in the first row in the respective colums and fill every single cell by VBA one by one. The formula in the respective previous cell should be converted into value. I'm not sure but I think the less formula there are in the Sheet the faster it works.

    After that the second, and finally the last column should be filled like this.

    Is there any solucion for my problem?

    I thought to do it with For...Next but I didn't manage it.

    By the way, I am not really new in VBA and I find my way in the Editor and I am familiar with the syntax. But I can't write my own code yet.

    Many thanks for your help


    conf

  2. #2
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: Fill cells with formula, one by one, AutoFill?

    Try this.

    Sub d()
    
       Dim LR&
       
           LR = Cells(Rows.Count, 1).End(xlUp).Row
            Cells(1, 24).Resize(LR).Formula = "YourFormula"  'Your formula for x column
            Cells(1, 25).Resize(LR).Formula = "YourFormula"  'Your formula for y column
            Cells(1, 26).Resize(LR).Formula = "YourFormula"  'Your formula for z column
              
               Range("X1:Z" & LR).Value = Range("X1:Z" & LR).Value
               
               
               
    End Sub
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Fill cells with formula, one by one, AutoFill?

    I can't see how using VBA would be quicker. Switch Calculation to manual, then re-calculate only when you need to
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #4
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Fill cells with formula, one by one, AutoFill?

    Hello JapanDave,
    thanks for your reply. It works excellently.

    But unfortunately this is not what I was looking for. I wanted to caculate every cell individually because the Array Formula require some time to calculate each time when it starts calculating.


    With your code it takes the same time as I would fill it manually.

    Do you have any further idea?

    Thank you for your help!

    conf

  5. #5
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Fill cells with formula, one by one, AutoFill?

    Hello Roy,
    I'm not sure but I think it would be faster if there is only one cell with a formula inside. The results in the colums of the respective row depend on each other.

    I can't upload it, the data are quite sensitiv.

    Thanks for your reply.

    conf

  6. #6
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Fill cells with formula, one by one, AutoFill?

    Ah, I forgot to mention that sometimes the application hang during calculation. I think this happens because of the CPU-intensive formula.

  7. #7
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: Fill cells with formula, one by one, AutoFill?

    Post a workbook if you can?
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  8. #8
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Fill cells with formula, one by one, AutoFill?

    Here you are, it's a simple copy of my sheet. Imagina how long it will work if you have thousands of rows and a plenty of columns to calculate.
    Attached Files Attached Files

  9. #9
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Fill cells with formula, one by one, AutoFill?

    llThat number of array formulas will be slow. You can switch calculation to manual, then when necessary just calculate a specific cell or range or range of cells

    Cells(1, 1).Calculate
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  10. #10
    Registered User
    Join Date
    02-11-2012
    Location
    Munich
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Fill cells with formula, one by one, AutoFill?

    Thanks Roy,
    I have to go on looking for another way. Thanks all for your effort!

    Have a nice day!

    conf

  11. #11
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Fill cells with formula, one by one, AutoFill?

    Why don't you simply sort your sheet ? first A, second B, third D ?



+ 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.2.0