+ Reply to Thread
Results 1 to 2 of 2

Trying to put results from Array back into Table after running through If Else If Loop

  1. #1
    Registered User
    Join Date
    08-30-2023
    Location
    Ottawa, Canada
    MS-Off Ver
    M365
    Posts
    1

    Trying to put results from Array back into Table after running through If Else If Loop

    Hi,

    I will preface this by saying that I have a rudimentary knowledge of excel/VBA macros that usually is enough to accomplish what I try to do, it might not be the most efficient code or even the best way of doing something but I usually can get things to work as I want them.

    The attached Workbook will show a very basic worksheet with basic company and contract data in columns A to G, columns I,K,M,O are the columns I am trying to populate using the data found in the rest of the columns (Q through the end of the Tablerow). These columns need to be ran through a loop to collect and sum up all Invoices in current row for each Quarter (Quarter dates are specified in code)

    Image Snipe.PNG

    The data consists of a invoice date and a invoice total amount. My original thought process was to load the table data all into an array, breakdown each set of invoice data (i.e. Data and Total) using Redim and size of the array. Then setup a loop to go through and collect the appropriate data and assigned the value from the DataArray position for the appropriate variable. This is where I am sure things could be done more efficiently as I then run all these variables through IF statements to check which quarter each invoice date falls under and add to another variable to collect. I figured once all these were collected, I could spit it back out into the current row column I,K,M,O. and the have the loop go through the rest of the rows and do the same thing. This is where I ran into trouble as I couldn't figure out how to a) Put the results back into current row b) loop back start the process all over again. The next i in my code seems to start the process over but without clearing the variables it overwrites the ones that were from the first time through the loop and the results are lost.


    Any pointers or assistance would be appreciated. Excel file is attached.

    Thanks
    Dan
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-25-2023
    Location
    AUstralia
    MS-Off Ver
    2021
    Posts
    14

    Re: Trying to put results from Array back into Table after running through If Else If Loop

    At first glance i would say create a pivot table from the data you are interested in (do it through VBA) and then reference the specific data from within the Pivot table - you have essentially had the Pivot table do all the hard work of defining what falls into each quarter/period etc.

    Craig

+ 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. [SOLVED] VBA code to loop through a table & show only rows that contain search results
    By blue_clouds_mountain in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-14-2021, 08:07 AM
  2. check condition in a loop and store results in an array
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-23-2018, 07:00 AM
  3. Array formula only pulling back half of the results
    By drc01051994 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-27-2017, 11:03 AM
  4. Replies: 1
    Last Post: 04-27-2017, 10:26 AM
  5. Loop through pivot table field and paste results in next row
    By DCLT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2015, 03:17 PM
  6. [SOLVED] Running Loop in an Array
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2014, 06:15 PM
  7. Loop new messages containing a table, populate a dynamic array, paste array to Excel
    By laripa in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2013, 07:20 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