+ Reply to Thread
Results 1 to 5 of 5

Help with VBA Loops

  1. #1
    Registered User
    Join Date
    06-05-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    13

    Help with VBA Loops

    I am fairly inexperienced with VBA, so I'm having issues understanding exactly how to program two loops.

    I have two charts (chart A and chart B) that I want to pull data from into a calculation sheet and then copy the output into the output sheet.

    Chart A and B have entries in the vertical direction, that I need to compare in the calculation sheet in a 2 x 2 matrix. The first loop I need is for data to be pulled in the vertical direction from Chart B and placed in the calculation sheet, for one Chart A value (which I would also like to be automatically pulled from its respective sheet). The second loop I need is for when all of the Chart B entries are completed, VBA automatically moves on to the next Chart A value and repeat the process by comparing all the Chart B values. This needs to continue until all Chart A values (~6,000) have been compared to Chart B values (~160).

    Finally, after each 2 x 2 matrix is solved, I need those values to be copied into the output sheet - so this could potentially be a third loop?

    Thanks in advance!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,903

    Re: Help with VBA Loops

    "Chart A and B have entries in the vertical direction" What does this mean? What type of charts are they?

    Charts are just a graphical depiction of data. They do not contain data. If you want to access the data that is used to make a chart then you will need to have code read that part of a worksheet, not the chart.

    "I need to compare in the calculation sheet in a 2 x 2 matrix" What is "the calculation worksheet"? What kind of comparison do you want to do? What are each of the four elements in the matrix? "after each 2 x 2 matrix is solved" What do you mean by "solved"? Are you trying to solve simultaneous equations for a variable?

    The description here is not specific enough to give you any actual code to do what you want. I suggest you provide an Excel file with an example of what you are describing, and a mock-up of what you want the result to look like.

    The paper clip icon does not work for attachments. Instead, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-05-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    13

    Re: Help with VBA Loops

    I apologize for the vague and poor description. I have attached a mock version of the set up I have.

    I have Chart A and Chart B (which are really just sheets) with x and y values. I need to plug the x and y values into the calculation sheet, where the respectful value will be displayed in C6 on the Calculation sheet. I need to take that value in C6, and plus it into its place on the Output Sheet. For example, if I wanted to compared ID 1's values (from A Chart) to Place 2 values (from B Chart), I want the resulting number to go in the C2 spot on the Output sheet. I need this process to repeat so that every ID and Place values are compared.

    Here is my code, but it doesn't work how I want it to. This is from the actual worksheet, so the cell references are a bit off:

    Please Login or Register  to view this content.
    Also not opposed to simply by passing the calculations sheet and just doing the calculation in the VBA coding -just not sure how to recreate the formula.

    Hope this is more clear. I really appreciate your help!

    Kara
    Attached Files Attached Files
    Last edited by 6StringJazzer; 08-03-2018 at 08:32 PM. Reason: Added section about open to doing the calculations within the VBA coding; Mod added code tags

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,903

    Re: Help with VBA Loops

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,671

    Re: Help with VBA Loops

    Please Login or Register  to view this content.


    A_Chart ='A Chart'!$B$2:INDEX('A Chart'!$C:$C,COUNTA('A Chart'!$C:$C))
    B_Chart ='B Chart'!$B$2:INDEX('B Chart'!$C:$C,COUNTA('B Chart'!$C:$C))
    Last edited by protonLeah; 08-04-2018 at 12:58 AM.
    Ben Van Johnson

+ 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. Loops within loops looping
    By Memphismark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2017, 12:21 PM
  2. VBA Loops / IF
    By ddbroadhead92 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-28-2016, 11:16 AM
  3. [SOLVED] Help with Loops
    By omagoodness in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2016, 06:27 PM
  4. Loops within loops?
    By Coeus in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-21-2013, 09:55 AM
  5. [SOLVED] Help with do until loops.
    By etuckram in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2013, 08:15 AM
  6. Loops and IFs
    By nyum in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 06:45 AM

Tags for this Thread

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