VBA/Formula needed for a complicated filter/data pull - Excel 365

justme101

Board Regular
Joined
Nov 18, 2017
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have one file where different products are listed in a column and along those rows, for each product, the type of pricing being offered is given for all the weeks of the year. Now, the pricing names can be varied, like discounted_1, discounted_2 etc. depending on what type of discount is being given. But, the thing which remains constant is that if there is no discount for a particular week, the words "Set price" appear for that week and product (it can be set price_1, or set price_2, but the words "set price" will be in that cell). A sample of the file is shown below (sorry my xls2bb is not working properly, so can't upload the file here).

Untitled.jpg


Now, the ask here is to get data for all these products (all unique line items) into a different sheet, with only the weeks where ANY kind of discount is given and the start date and end date as well from the top rows. It should look something like this.

Untitled2.jpg


I have tried all my *limited* knowledge of formulas and VBA to accomplish this, but I can't come up with something to solve it. If you can help me out to accomplish this, it would not be less than a miracle for me (It's that time of the year as well). Any formula, or VBA will work with me. Thank you, in anticipation.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
Excel Formula:
=LET(a,LEFT(C4:N9,9)="Set price",HSTACK(TOCOL(IF(a,x,B4:B9),3),TOCOL(IF(a,x,C4:N9),3),TOCOL(IF(a,x,C1:N1),3),TOCOL(IF(a,x,C2:N2),3)))
 
Upvote 0
How about
Excel Formula:
=LET(a,LEFT(C4:N9,9)="Set price",HSTACK(TOCOL(IF(a,x,B4:B9),3),TOCOL(IF(a,x,C4:N9),3),TOCOL(IF(a,x,C1:N1),3),TOCOL(IF(a,x,C2:N2),3)))
Hi Fluff,

I tried this, but it gave me a #NAME? error. I put the formula at the end of the data in the 1st screenshot, in cell O4.

Untitled3.jpg
 
Upvote 0
Ok, you probably don't have some of those functions yet.
How about
Excel Formula:
=LET(da,B4:B9,db,C1:N2,dc,C4:N9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),x,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4},INDEX(da,INT(s/c)+1),x,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,LEFT(x,9)<>"set price"))
 
Upvote 0
Ok, you probably don't have some of those functions yet.
How about
Excel Formula:
=LET(da,B4:B9,db,C1:N2,dc,C4:N9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),x,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4},INDEX(da,INT(s/c)+1),x,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,LEFT(x,9)<>"set price"))

This works great, but probably just needs a minor modification. The words "set price" might not be always just that, it may be like for e.g. "set price 1", "2_set price", "set price $2" etc. Basically the cell will have the words "set price" but with numbers or prices before or after them.
 
Upvote 0
In that case try
Excel Formula:
=LET(da,B4:B9,db,C1:N2,dc,C4:N9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),x,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4},INDEX(da,INT(s/c)+1),x,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,ISERR(SEARCH("set price",x))))
 
Upvote 0
In that case try
Excel Formula:
=LET(da,B4:B9,db,C1:N2,dc,C4:N9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),x,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4},INDEX(da,INT(s/c)+1),x,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,ISERR(SEARCH("set price",x))))

Well, Mr. Fluff, you, sir, are a genius. This works perfectly. and 80% of this formula is completely new to me. I thought I knew excel, but I better get to studying again :biggrin:. Any references, where I can improve my skills, with formulas specifically?
In that case try
Excel Formula:
=LET(da,B4:B9,db,C1:N2,dc,C4:N9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),x,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4},INDEX(da,INT(s/c)+1),x,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,ISERR(SEARCH("set price",x))))

Also, the data was modified (by the HQ) and now they need have some extra columns on the left, which also needs to be pulled in along with the solution you provided. I am putting the updated screenshot below, but if you want me to create a new thread, I'll be happy to do that.

1669876609806.png


So, in this case along with the product, the type of pricing, the start and end date, the individual time slot, and stage allotment also needs to be given, which is important. So, if I take product A as an e.g. for wk1, there will be two lines created in the output, something like this:

1669876593182.png


Really appreciate the help here. Thank you.
 

Attachments

  • Untitled4.jpg
    Untitled4.jpg
    154.1 KB · Views: 3
Upvote 0
How about
Excel Formula:
=LET(da,B4:D9,db,E1:P2,dc,E4:P9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),xa,INDEX(da,INT(s/c)+1,{1,2,3}),xb,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4,5,6},xa,xa,xa,xb,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,ISERR(SEARCH("set price",xb))))
 
Upvote 0
How about
Excel Formula:
=LET(da,B4:D9,db,E1:P2,dc,E4:P9,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),xa,INDEX(da,INT(s/c)+1,{1,2,3}),xb,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4,5,6},xa,xa,xa,xb,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,ISERR(SEARCH("set price",xb))))

This formula definitely works, but assumes the data is till row 9 (as I gave you the sample data till that row no.), but it will definitely be much more than that, not sure of the exact number. So, I tried to modify the number of rows to an estimate, like 900, but it pulls up the blanks as well and shows them as 'zeroes'. Anything to remove those extra non-data cells?
 
Upvote 0
How about
Excel Formula:
=LET(da,B4:D900,db,E1:P2,dc,E4:P900,c,COLUMNS(dc),s,SEQUENCE(c*ROWS(dc),,0),xa,INDEX(da,INT(s/c)+1,{1,2,3}),xb,INDEX(dc,INT(s/c)+1,MOD(s,c)+1),xx,CHOOSE({1,2,3,4,5,6},xa,xa,xa,xb,INDEX(db,1,MOD(s,c)+1),INDEX(db,2,MOD(s,c)+1)),FILTER(xx,(ISERR(SEARCH("set price",xb)))*(xb<>"")))
 
Upvote 0
Solution

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top