+ Reply to Thread
Results 1 to 17 of 17

Help needed simplifying code as procedure to long

  1. #1
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Help needed simplifying code as procedure to long

    Hi all

    Could you please help?

    I need to update 10 tables/matrix (pls see attached) based on cell values from the table which feed into sheet1 and then sheet2 will then provide the value that needs to go into the cell.

    Being a novice I googled some solutions but decided to go with the basic/simple/noob friendly option below. The problem is that the code for all of the 10 tables makes it too long for a sub.

    Is there a way of simplifying the code?

    I hope this makes sense.

    Thanks in advance
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help needed simplifying code as procedure to long

    I do not know the reason for keep copying in to D9, one version

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help needed simplifying code as procedure to long

    hi johnny_p,

    there is no code in the posted file. The posted code looks a bit weird in all lines starting with Worksheets("sheet1").Range("D9").Value. In all the nine lines you overwrite the value in sheet 1 D9 with a new value from sheet 2: firstly it equals to A17 then A18 then A19.

    In order to get help you need to provide instructions for all cell values in question.

  4. #4
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Thanks for taking the time to look

    I have uploaded the file again with the code.

    In the basic sense I have to keep copying the cell values within each year/matrix to sheet one where a formula will then produce the output which needs placing into sheet2.

    For example

    yr1 Matrix - First box = Cell B17

    Sheet2 B16 to go to Sheet1 D11 Then
    Sheet2 A17 to go to Sheet1 D9

    This gives me a figure in sheet1 I9 which needs to go to B17.

    I then need it to work out the rest of the matrix going down from A17-A25 and across from B16-K16.

    Then the same again for the rest of the years.

    I hope this makes sense. I can confuse myself most of the time.

    Thanks again in advance
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help needed simplifying code as procedure to long

    the sheet1 is empty. As far as I understand you transfer two values there to use them in calculation. Can you show working workbook with calculation on sheet1 and fill a couple of value in sheet2 Year1?

  6. #6
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Unfortunately the calculations also depend on loads of other cells in other sheets so no real point in putting it in. The values are all numbers

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    You may try:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Thanks

    This works but for only the range of of (A17:A25)

    How would I get it to then look at the next cell in Range (B16:K16) and put this in Sheet1 (D11)? And then start over again with your code but offset the cell to the next column i.e "C".

    Thanks again

    Quote Originally Posted by Izandol View Post
    You may try:
    Please Login or Register  to view this content.

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    Quote Originally Posted by johnny_p View Post
    This works but for only the range of of (A17:A25)
    This is only range in your code provided.

    Where is output from B16:K16 calculations to go?

  10. #10
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Sorry for any confusion.

    They would need to be offset (0,1) from rgCell.value until column K.

    Like a matrix, i,e sheet2 Cell E17 would be calculated from the inputs from E14 & A17.

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    Perhaps:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Boom, Works perfectly! Thank you

    Could you please don me one more favour. Could you please explain this line of code so that I can add other tables/matrix?

    Please Login or Register  to view this content.
    Thinking of adding another sub for each matrix and call upon each on when needed. Obviously each matrix has different cell inputs

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    Column A inputs for each table start in row 17 and are 14 rows apart, so:
    (n - 1) * 14 + 17
    returns 17,31,45 et cetera
    Same for inputs in row above except starting at 16. If the ten tables have different cell inputs (this is not obvious - row/column data may be different ) you do not require loop from 1 to 10. You may change matrix routine to accept input cells as arguments also.

  14. #14
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    I would be telling fibs if I said I fully understand. I'm half way there.

    I didn't realise that this works out the whole 10 tables. Thanks for this.

    I need to add another input to identify each table which will effect the outputs. Year table equates a year so 1-10.

    Would it be best to say each time you loop "Next N" change cell value to match the "N" loop number? Does this make sense?

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    Yes you may do that.

  16. #16
    Forum Contributor
    Join Date
    06-07-2013
    Location
    Bournemouth
    MS-Off Ver
    Excel 2003
    Posts
    158

    Re: Help needed simplifying code as procedure to long

    Sorted.

    Thank you very much for your time, effort and skills.

  17. #17
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Help needed simplifying code as procedure to long

    You are welcome.

+ 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. Can anyone help with simplifying this super long Excel IF statement?
    By YPerez in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2013, 05:35 PM
  2. Replies: 3
    Last Post: 01-10-2012, 07:23 PM
  3. Procedure Too Long
    By Nick3535 in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 10-08-2010, 09:02 PM
  4. Macro code too long: "Procedure too large" Error
    By nachousa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 03:16 PM
  5. Code needed that will run a check procedure every 5 minutes.
    By Zjak in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-05-2006, 10:38 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