+ Reply to Thread
Results 1 to 7 of 7

Sum part of a row in a two dimensional array

Hybrid View

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Sum part of a row in a two dimensional array

    Hi guys,

    is there an easy way to sum part of a row of a two dimensional array in memory?

    Situation:
    1) I put 150 rows by 130 columns of the worksheet into an array in memory
    2) I do webscrapes and paste the results into the array rather than the worksheet
    3) I want to sum part of each row (for example, row 20, columns 24:27) and store that into column 23 of row 20 in the array

    when I'm all done, I paste this back into the worksheet.

    My array is called 'sht'

    I tried the following, but that doesn't work.
    sht(20, 23) = Application.Sum(Sht(20,24),Sht(20, 27))
    What am I doing wrong here?

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Sum part of a row in a two dimensional array

    Perhaps try
       Sht(20, 23) = Application.Sum(Application.Index(Sht, 20, [{24,25,26,27}]))
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sum part of a row in a two dimensional array

    maybe just
    sht(20, 23) = sht(20, 24) + sht(20, 25) + sht(20, 26) + sht(20, 27)

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Sum part of a row in a two dimensional array

    Thanks, PCI, that works flawlessly!

  5. #5
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Sum part of a row in a two dimensional array

    Thanks PCI & nilem,

    the problem is that the '24' and '27' are coming from variables.

    So it actually is as below
    sht(20, 23) = application.sum(sht(20, x), sht(20, y))
    my apologies, I should have made that clear in my original post.

    I know I could loop through it, by saying
    z = x
    do until z = y + 1
    sht(20, 23) = sht (20, 23) + sht(20,z)
    z = z + 1
    loop
    But I prefer to not loop

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Sum part of a row in a two dimensional array

    Try again

       Sht(20, 23) = Application.Sum(Application.Index(Sht, 20, Evaluate("row(" & x & ":" & y & ")")))

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Sum part of a row in a two dimensional array

    Good news, you're 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. [SOLVED] Convert one dimensional array into two dimensional array
    By mohammed sabr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-26-2015, 10:34 AM
  2. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  3. Populate a Single Dimensional Array with two Dim Array (matrix)
    By Benjamin1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2011, 12:49 PM
  4. Creating a 2-dimensional array from a 1-dimensional list
    By guywithcamera in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-27-2008, 06:34 PM
  5. Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM
  6. Transferring part of a multi-dimensional array to a range in VBA
    By Bob J. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2005, 11:05 AM
  7. [SOLVED] Create One-Dimensional Array from Two-Dimensional Array
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 05:06 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