+ Reply to Thread
Results 1 to 73 of 73

VBA to split data and apply a percentage sum to total values

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    VBA to split data and apply a percentage sum to total values

    Morning,

    I have the following code to do the following;

    Copy orignal data to a workbook
    Filter by a reference 'A214'
    Copy each entry of A214 and reference A200, A210 & A220.

    What i need to do now is identify the percentage (user input on sheet called 'Start') and apply a sum of the (A214) value * the percentage on the start sheet to give me a split amount for A200, A210 & A220, this will then tie back to the orignal A214 values?

    Hope this makes sense,

    Code below;
    Please Login or Register  to view this content.
    I have attached sample data, a quick repsonse would be greatly appreciated, i need to get this project out by today.
    Attached Files Attached Files
    Last edited by kenadams378; 08-01-2012 at 09:58 AM.

  2. #2
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    All i am after is some code as to how i get the macro to apply a sum to to the original data multiplied by the percentage on the start sheet?

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    So first you want a sum in the original data tab right for all the numerical values?

    I had provided you the code for the sum in the other request. Didnt it work for you?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    No, the original data tab is total figure the A200, A210, A220 data needs to reconcile back to.

    The values of A200, A210, A220 data need to be the percentage of the original data..

    The code worked but i need to show the values on each line based on a percentage of the original value.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    So the subtotals created by the macro should be replaced by values which are a %age of the original value?

    Or

    Should the values shown in the various columns like V, AC, AD etc be changed to be a % of the original value?

  6. #6
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    The values shown in the various columns like V, AC, AD etc be changed to be a % of the original value.

    The percentage will be on the 'Start' sheet.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Ok, got it (i think )

    Can you list out the columns that need to be changed?

  8. #8
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    V, w, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an,

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    One more question - is there any unique identifier in the data in the tabs A200, A210 and A220 that ties back to A214?

    What if the data in A214 gets sorted (by mistake) and no longer matches with the data in the subsequent tabs, how do we ensure that the % applied are correct?

  10. #10
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    There won't be a specific identifier but once i have the code, all the cells and filters will be locked down so can't be edited..

    ---------- Post added at 01:55 PM ---------- Previous post was at 01:01 PM ----------

    Does that make sense?

    ---------- Post added at 02:42 PM ---------- Previous post was at 01:55 PM ----------

    How long do you think it will take to produce this code?

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    So you will be running my earlier part of the code which separates the data and then creates subtotals for each tab, right?

    Or will the subtotals be put after the code that i will give you, will be run?
    Last edited by arlu1201; 07-30-2012 at 09:54 AM.

  12. #12
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Yes, the seperation will still be completed but then the percentage sum will need to be completed on the seperated data.

    There is no need for the sub totals anymore or highlighted lines, just need a total at end of each column on each tab.

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    So the subtotals code will not be used but will need to be changed to a totals row?

  14. #14
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Yep, total of all the data on each tab..

    ---------- Post added at 03:32 PM ---------- Previous post was at 03:11 PM ----------

    Sorry, hope that made sense, i meant a total on each tab.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    This is the updated code
    Please Login or Register  to view this content.
    Do you want the totals for the same columns listed in post 8?

    Do you want the totals for original data and the 3 tabs?

  16. #16
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Yes, totals on each tab for each column with a value

  17. #17
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    So all numerical columns not just the ones you have listed out?

  18. #18
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Sorry all ones i have listed;

    I have tried the code but gettting an error;

    Please Login or Register  to view this content.
    Also it seems to copy the original data to the sheet called Start not the Original Data tab.

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    What error are you getting?

    Actually, this code has been developed as a consolidated effort in 2-3 threads. So each time, you might have provided varying sheet names, hence the confusion.

    You can let me know how your final workbook will look like and i can help you to correct the code.

  20. #20
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Also, i can't see where it is using the percentage from the 'start' sheet, the 3 values on the 'start' sheet are;

    A200 - Cell D6
    A210 - Cell D9
    A220 - Cell D12

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    You mean you are seeing the text "Cell D6" and "Cell D9" in the Start page?

    I ran your code in the sample file you uploaded and it works fine.

    I guess the confusion lies in the varying sheet names. Once you give me the info as of post 19, even this will fall in place.

  22. #22
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Ok,

    Workbook is as follows;

    Start
    Original Data
    A200
    A210
    A220

    The Start sheet has the percentages on it in the cells mentioned.
    Original Data has filtered A214 data on it
    A200 has the exact copy of A214 but with A214 references replaced with A200
    A210 has the exact copy of A214 but with A214 references replaced with A210
    A220 has the exact copy of A214 but with A214 references replaced with A220

  23. #23
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    What is the error you received after you ran the code?

    Will this format
    Start
    Original Data
    A200
    A210
    A220

    be the final format?

  24. #24
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Yes that will be final format

  25. #25
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    What is the error you received after you ran the code?

  26. #26
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Will run it again tomorrow and report back

  27. #27
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Please Login or Register  to view this content.
    I now have an error message with this code, saying there is a lack of resources

  28. #28
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Are you able to cover this off today at all?

  29. #29
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Quote Originally Posted by kenadams378 View Post
    Please Login or Register  to view this content.
    I now have an error message with this code, saying there is a lack of resources
    Looks like its huge data that is being copied. Will devise an alternate code for this portion.

    Did the values populate after calculating the % of the total?

  30. #30
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    No, the code just stops at that point!

  31. #31
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Try this code and let me know if it poses any errors -
    Please Login or Register  to view this content.

  32. #32
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Please Login or Register  to view this content.
    Not happy with this part, error message reads - subscript out of range.

  33. #33
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    You had mentioned that you wanted to filter the data and move it to original (filtered). Do you want to still do that?

    If yes, we need to create a sheet called original(filtered) and then the code will work fine.

  34. #34
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    The data on the orignal tab just needs to be filtered, doesn't need to be moved anywhere after being filtered...

    ---------- Post added at 09:45 AM ---------- Previous post was at 09:44 AM ----------

    Data is still been copied to the 'Start' sheet, this shouldn't happen, all the original data should be on the 'original data' tab...

  35. #35
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Try this
    Please Login or Register  to view this content.

  36. #36
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Not happy with this bit;

    Please Login or Register  to view this content.
    subscript out of range again

  37. #37
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    This is weird.

    Does your Start sheet have A200 in A3, A210 in A4 and A220 in A5?

    Do the sheet names match with the above 3?

    I ran the code at my end and it worked fine.

  38. #38
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    A200 is in cell B6
    A210 is in cell B9
    A220 is in cell B12

    Sorry for the confusion at back and forth emails....

  39. #39
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Hmmm thats what caused the error. Your sample file had the data how i had mentioned.

    Change this line from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  40. #40
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Still doesn't like this line;

    Please Login or Register  to view this content.
    Out of range still

  41. #41
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    When you get the error and see the above row highlighted in yellow, can you hover your mouse onto sname and tell me what value you see?

    Same for lrow.

  42. #42
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    You should fully qualify
    Please Login or Register  to view this content.
    Should be:
    Please Login or Register  to view this content.
    Otherwise it is counting rows on the activesheet

  43. #43
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    No Kyle.

    I have already qualified the row much earlier in the code. And it cannot be worksheets("Sheet1") in this case.

  44. #44
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    I've edited. And no, you haven't; notice the .Rows

  45. #45
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    OH yeah, thanks Kyle.

    Kenadams,

    Change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  46. #46
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    no probs , but that still won't work as you don't have a with block for the worksheet, only the workbook, it should be:
    Please Login or Register  to view this content.

  47. #47
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    The whole code is in post 31. I have qualified it there just below
    Please Login or Register  to view this content.
    hence i didnt qualify it again.

  48. #48
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    lrow = .Worksheets(sname).Range("A" & .Rows.Count).End(xlUp).Row

    Doesnt like the .rows elemnt of the code..

    Error message is - Compile error - method or data memeber not found;

    Full code edited below;

    Please Login or Register  to view this content.

  49. #49
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    If you remove the "." before the Rows, what error are you getting?

    When you get the error, whats the value for sname and lrow when you hover the mouse over it?

  50. #50
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    @arlu, no, you set the workbook not the worksheet.

    There is no Rows property of the workbook object as Ken has just found out.

    Therefore you must further qualify the worksheet. In this context:
    Please Login or Register  to view this content.
    or even, since you already have the workbook set in the parent with block:

    Please Login or Register  to view this content.

  51. #51
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    So where am i editing this code;

    Please Login or Register  to view this content.

  52. #52
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    replace
    Please Login or Register  to view this content.
    with it

  53. #53
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Ok, i get it.

    Ken,

    Try this final code -
    Please Login or Register  to view this content.
    Note: I ran the macro when it was not qualified and it ran fine. I wonder why it fluctuates like this.
    Last edited by arlu1201; 08-01-2012 at 07:50 AM.

  54. #54
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    Because you had the correct sheet selected

    Unqualified worksheet code, runs on the active sheet, always try and be as explicit as possible - leaves less room for errors.

  55. #55
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Sorry, it doesn't like;

    Next i near the end of the code;

    Error is - Compile error (next without for)

  56. #56
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Oops sorry i have edited the code in post 53.

  57. #57
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Sorry, not happy with bit now, sorry my knowledge on this is vague...
    Please Login or Register  to view this content.
    Error - Subscript out of range

  58. #58
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    Then whatever's in .Worksheets("Start").Range("A" & i).Value isn't the name of a sheet in that workbook

  59. #59
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Let me run the macro (after changes) on your original file and attach it here. Maybe you can have a look and see.

    ---------- Post added at 04:55 PM ---------- Previous post was at 04:51 PM ----------

    There was a slight error in the above code. It was missing the Step 3 in for i = 6 to 12.

    Now you should be able to run it without any issues. If not, i will run it at my end.

  60. #60
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    There isn't anything in column A, not sure what the i refers too.

  61. #61
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Let me explain this part of the code to you.
    Please Login or Register  to view this content.
    Pcent takes the value of cell B6 from the Start sheet and sname takes the value from A6.

    Then the code moves down 3 rows and takes the values from A9 & B9 and then A12 & B12.

  62. #62
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Right that makes sense, i have ran it again and have an error on;

    Please Login or Register  to view this content.
    Show this be With.Workbook(sname)???

  63. #63
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    When you hover your mouse over sname, what value is it showing?

  64. #64
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    When i hover i get;

    .Worksheets(sname) = subscript out of range

  65. #65
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA to split data and apply a percentage sum to total values

    in the locals window, what value does sname have and is there a worksheet with the same name in the workbook?

  66. #66
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Can you attach your file? I have made some more modifications to the code in post 53. Also i ran the macro at my end and attaching it here.
    Attached Files Attached Files

  67. #67
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    I can't the sheet is too big, if you attachment runs fine, i can just copy the file and use this as my live file..

    ---------- Post added at 12:54 PM ---------- Previous post was at 12:52 PM ----------

    What are the differences between module 1 & 2 in your macros?

    ---------- Post added at 01:01 PM ---------- Previous post was at 12:54 PM ----------

    There isn;t anything in the locals window....

    ---------- Post added at 01:07 PM ---------- Previous post was at 01:01 PM ----------

    Found it, the sname value is just ""

  68. #68
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Right click on module and remove it. Module 2 is the right one.

    Also in my code the CHDir statement has a ' in front of it. Remove that '.

    The sname value cant be "". This is what is causing the error.

    ---------- Post added at 05:45 PM ---------- Previous post was at 05:37 PM ----------

    Oops i get it. In your start page, do you have the sheet names like A200, A210, etc in column B and the % in column C? As per your original attachment, it was in column A & B not B & C.

    So this code should be changed from
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    In both your file and mine.
    Last edited by arlu1201; 08-01-2012 at 08:12 AM.

  69. #69
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Sorry for this again;

    I am now using your file, the sheet names A200, A210 & A220 are in column A & % are in Column B.

    Seems to work fine now it's just not happy with the percentage codeing as follows;

    Please Login or Register  to view this content.
    Error is Run-time error 438

    Object doesn't support this property or method.

  70. #70
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    You have not run the updated code.

    I had changed it. I guess this thread is very long so its creating confusion.

    Updated code here
    Please Login or Register  to view this content.
    This code considers that Sheet names A200, A210 are in column B and % in column C.

  71. #71
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    I have a type mismatch error with this line;

    Please Login or Register  to view this content.
    Nothng appears when hovering over it either

  72. #72
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA to split data and apply a percentage sum to total values

    Did you try running it in my workbook? I ran the code again and it works fine.

    ---------- Post added at 06:10 PM ---------- Previous post was at 06:06 PM ----------

    I added some code lines to make your code run faster.
    Please Login or Register  to view this content.

  73. #73
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to split data and apply a percentage sum to total values

    Brilliant. it works now!

    Thank you so much for your time...

    Going to run some output so will feedback any more errors!

+ 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