+ Reply to Thread
Results 1 to 13 of 13

dividing data equally between cells VBA

  1. #1
    Registered User
    Join Date
    01-25-2011
    Location
    Milan, Italy
    MS-Off Ver
    Excel 2007
    Posts
    62

    dividing data equally between cells VBA

    hello everybody.. I need a VBA code to do the following:

    in sheet 1 I have a range J8:J57. Here I have some numbers that I need to be equally divided into cells (in columns) in sheet 2. Right now I am using the following formula: =ROUND(sheet1!$J$9/96;14). I then pull this formula down 96 cells to have the result. Then I move on to the next cell and do the same with the following formula: =ROUND(sheet1!$J$10/96;14).

    This takes forever and, most important, is bound to create a problem if one of my colleagues deletes the formula from the cell.

    Is it possible to have VBA to do the job by selecting the cell and its destination range (ranges can vary between 96 and 125 cells)...?

    Also, is it possible to have the function update the destination cells whenever a change is made on sheet1?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: dividing data equally between cells VBA

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    01-25-2011
    Location
    Milan, Italy
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: dividing data equally between cells VBA

    Hello xladept,

    attached please find a sample file. On sheet1 you can see some data the way it is presented. Sheet 2 is where all happens. Right now I use the "round" formula. I would like to have VBA to do that. Please keep in mind that the number of cells, on sheet2) that need to have the data may vary from 90 to 150. This variation is not sequential (like 90, 91, 92 and so on)
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: dividing data equally between cells VBA

    Please Login or Register  to view this content.
    Last edited by bsalv; 01-05-2014 at 08:19 PM.

  5. #5
    Registered User
    Join Date
    01-25-2011
    Location
    Milan, Italy
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: dividing data equally between cells VBA

    Hello bsalv, thanks for the reply. when I run your macro I see that numbers are placed also in a horizontal way. As you can see from my sample sheet this is not the case as the results are always vertical. And, also, how do I get the macro to automatically run when there are changes in any of the source cells?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: dividing data equally between cells VBA

    Hi Lauro,

    How can you tell how many variations should be for each sheet 1 entry?

  7. #7
    Registered User
    Join Date
    01-25-2011
    Location
    Milan, Italy
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: dividing data equally between cells VBA

    Hi XLAdept, it is a know data:

    the cells in sheet2 are CJ and CK

    268 to 363 (96)
    365 to 488 (124)
    490 to 614 (125)
    616 to 740 (125)

    and so on....

    please note that CJ and CK fetch data from different cells

  8. #8
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: dividing data equally between cells VBA

    see attachment
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: dividing data equally between cells VBA

    it's chinese

  10. #10
    Registered User
    Join Date
    01-25-2011
    Location
    Milan, Italy
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: dividing data equally between cells VBA

    Hi bsalv, this looks almost like the code I need... let me try to explain exactly what I need to achieve with the new sheet.

    Sheet1 first (weight) and second (loss) column is where I will insert the weights. This will, of course, vary, depending of what the warehouse prepares.

    Sheet2 is where I need to result to appear. The amount of cells where I need the weights and the loss to be divided are always the same. For instance Sheet1! A2 and B2 will always be divided between 96 cells. Sheet1! A3 and B3 between 124 cells. And also, the positions in Sheet2 where the data will start is always the same (for example sheet1!A2 will always be divided between cells from A1:A95 on Sheet2)

    I hope this makes more sense
    Attached Files Attached Files

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: dividing data equally between cells VBA

    Hi Lauro,

    Let me excuse myself from this thread - good luck!

  12. #12
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: dividing data equally between cells VBA

    i'm blonde what's your excuse ?

  13. #13
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: dividing data equally between cells VBA

    i added the number of cells in a 3rd column, because untill now i have no idea where i should find your numbers.
    Attached Files Attached Files

+ 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. Macro which sums up equally colored cells
    By Marina86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2013, 08:40 PM
  2. Excel 2007 : Spreading data equally
    By darkdan21 in forum Excel General
    Replies: 0
    Last Post: 04-06-2012, 07:21 AM
  3. Replies: 5
    Last Post: 02-24-2012, 11:48 AM
  4. Divide cell amounts between cells equally
    By hotwoz in forum Excel General
    Replies: 6
    Last Post: 07-08-2011, 05:54 AM
  5. Replies: 2
    Last Post: 06-14-2007, 05:18 PM

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