0

Good day to an amazing community,

I am trying to develop a macro to loop through two arrays. Here is an example of how the data is set up:

Raw data is found in C4:C1500

$ data is found in D4:D1500

Partial string values (originaly pulled from Raw data) are in E4:E13.

Categories the Raw data will organized into are in F4:F13

Below is the formula I pieced together as a proof of concept.

=IF(VLOOKUP(" * "&E4&" * ",$C$4:$C$1500,1,0)=ERROR.TYPE(#N/A),"Research",VLOOKUP(" * "&E4&" * ",$E$4:$F$13,2,0))

This works one line at a time, and only until the bottom of the short lists (without writing a massive nested statement). I'm trying to loop the Partial & Category values through the Raw data to then analyze the data by Category & $.

Example: Sheet1

Row Column C (C4:C1500) Column D (D4:D1500) Column E (E4:E13) Column F (F4:F13)
3 Raw Data $ Partial Data Category
4 210324Sales.BobParr.UT 785.54 BobParr Sales
5 ABCDEF.210324.SalesHelenParr.TN 214.46 HelenParr Sales
6 DashParr.WY.RR.210324 238.56 DashParr Research
7 Mgmt.NY.JackJackParr.210324 1,200.00 JackJackParr Management

Sheet2:

Rows Column B (B4:B13) Column C (C4:C13)
3 Category Total $
4 Sales 1,000.00
5 Research 238.56
6 Management 1,200.00

From there I will do another VLOOKUP( to SUM( expenses found in Sheet2.

I'm open to all suggestions for both cleaning up the testing formula, and will be grateful for all support with the VBA.

Thank you.

Richard VO

1 Answer 1

1

I don't see the need to use VBA. If you have Excel 365, you can combine FILTER, CHOOSECOLS and SUM functions to obtain the desired results. Adapt the following formula:

=SUM(CHOOSECOLS(FILTER(Sheet1!$C$2:$F$5,Sheet1!$F$2:$F$5=Sheet2!$B3),{2}))

Bring the formula down to fill the other cells.

5
  • CHOOSECOLS() wins. Nice formula =) But Sir, why have you used curly braces at the last, will it not work without it. {2}? Commented Mar 25 at 10:38
  • 1
    @MayukhBhattacharya The {2} is to select only the second column as the FILTER function is returning 4 columns. This make it easier to then sum the amounts. Commented Mar 25 at 11:01
  • 1
    Ok, but is it needed within curly braces. Commented Mar 25 at 11:02
  • 1
    @MayukhBhattacharya Not needed. Before using CHOOSECOLS, I hade planned on using two FILTER functions. o, I was using the curly braces with one of them, then kept it when I changed my formula. Commented Mar 25 at 11:08
  • alright understood sir Commented Mar 25 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .