+ Reply to Thread
Results 1 to 6 of 6

Formula or VBA to fill a specified number of cells

  1. #1
    Registered User
    Join Date
    01-07-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    92

    Formula or VBA to fill a specified number of cells

    This is a little tricky to explain so I've attached a spreadsheet which sould make things a bit clearer....

    In Sheet1 as attached cell B2 contains the number 15, I need the figures in B5:B16 (and possibly more in the future) to be divided by B2. Then the grid between C5:AB16 (which will grow if B2 increases) needs to be populated. Each Month begins in the column which corresponds to it (i.e. Month 1 in C, Month 2 in D, Month 3 in E etc.) and stops when it reaches, in the case of Sheet 1, 15 entries.

    Sheet2 illustrates what would happen were cell B2 to change to 18, and the results I am trying to achieve.

    Hopefully this makes enough sense for someone to be able to help me!!

    Thanks in advance
    Attached Files Attached Files
    Last edited by jsolder; 12-02-2014 at 12:05 PM. Reason: Solved

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Formula or VBA to fill a specified number of cells

    Try this - put the code in the worksheet module, not a general module;
    Please Login or Register  to view this content.
    This will update the formulae whenever cell B2 changes.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert boopathiraja's Avatar
    Join Date
    07-12-2013
    Location
    Coimbatore,TamilNadu, India
    MS-Off Ver
    Excel 2007, 2013, 2016, 365
    Posts
    1,455

    Re: Formula or VBA to fill a specified number of cells

    Hi, Apply this in c5 and drag it down and across

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Click just below left if it helps, Boo?ath?

  4. #4
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Formula or VBA to fill a specified number of cells

    Hi,
    Try this for one sheet..
    Please Login or Register  to view this content.
    For all Sheets, Try this..
    Please Login or Register  to view this content.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  5. #5
    Registered User
    Join Date
    01-07-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Formula or VBA to fill a specified number of cells

    Olly thanks for your help! Seems to work almost perfectly...
    My only issue is that if the number in B2 decreases then values end up remaining from the previous calculations, I tried modifying the code to clear the contents before it updates the formulae but hit a bunch of errors. Where am I going wrong?
    Please Login or Register  to view this content.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Formula or VBA to fill a specified number of cells

    My original code DOES clear the existing formulae first, with this line:
    Please Login or Register  to view this content.
    Make sure you have enabled application events by running the following code, then test my code again:

    Please Login or Register  to view this content.

+ 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. Fill number of cells with my value
    By ge2kaslt in forum Excel General
    Replies: 3
    Last Post: 10-31-2012, 04:55 AM
  2. Replies: 1
    Last Post: 09-07-2011, 05:57 PM
  3. Fill blank cells with 0 or alternative number
    By Spellbound in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2008, 10:27 AM
  4. Replies: 5
    Last Post: 06-12-2008, 12:39 PM
  5. [SOLVED] Macros fill cells regardless of row number
    By Trixie in forum Excel General
    Replies: 7
    Last Post: 03-24-2006, 07:41 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