Taking the right amount out of more than one condition

JimmyBambo

New Member
Joined
Dec 8, 2018
Messages
30
Hi friends,
I took picture of my problem as it is easier for me to explain on it, as I cant fully solve this problem.
So I have to determine percentage of discounts (F row) according to conditions in table on right side.
1) For different suppliers I have different discount rates on different dates,
2) For some products of suppliers I have also different discount rates.
So for example, if producer is Coca Cola, product is Coca Cola, date of invoice is 28.01.2018, discount is 5%. If it was product Fanta or Sprite, discount would be 7%.
I hope so that this is solvable, thank you in advance (y)

jTyGvDN
V57Xzxg.png
 
I am watching this what you made, and it looks like it was exactly what I was searching for.
Can you give me explanation how did you get helper1 values?
And what formula did you use for discount column?


I would really appreciate if you can share whole file with me so I can see it and try to implement it in my format.


Thank you. (y)(y)
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
If your happy to use some code, try this for results in column "F".
Code:
[COLOR="Navy"]Sub[/COLOR] MG08Dec53
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("H3"), Range("H" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False

[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Txt = Dn.Value & Dn.Offset(, 1).Value
    [COLOR="Navy"]Set[/COLOR] .Item(Txt) = Dn
[COLOR="Navy"]Next[/COLOR]

[COLOR="Navy"]Set[/COLOR] Rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
Txt = ""
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
  [COLOR="Navy"]For[/COLOR] n = 0 To 1
   Txt = IIf(n = 0, Dn.Value & Dn.Offset(, 1).Value, Dn.Value)
        [COLOR="Navy"]If[/COLOR] .exists(Txt) [COLOR="Navy"]Then[/COLOR]
           [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] True
                [COLOR="Navy"]Case[/COLOR] Dn.Offset(, 2).Value > Range("L2").Value
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "L"), "0.00%")
                
                [COLOR="Navy"]Case[/COLOR] Dn.Offset(, 2).Value <= Range("L2") _
                And Dn.Offset(, 2).Value > Range("K2")
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "L"), "0.00%")
            
                [COLOR="Navy"]Case[/COLOR] Dn.Offset(, 2).Value <= Range("K2") _
                And Dn.Offset(, 2).Value > Range("J2")
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "K"), "0.00%")

                [COLOR="Navy"]Case[/COLOR] Dn.Offset(, 2).Value <= Range("J2").Value
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "J"), "0.00%")
           [COLOR="Navy"]End[/COLOR] Select
           [COLOR="Navy"]Exit[/COLOR] For
        [COLOR="Navy"]End[/COLOR] If
  [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Dn

[COLOR="Navy"]End[/COLOR] With
Application.ScreenUpdating = True
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
buyersupplierproddatedishelper1
CSCOCcoca28/01/20185COC
CSCOCfan23/07/20188COCfancolumn Kcolumn P
CSPEPpepsi16/08/20189PEP
CSNESnesc21/11/20183NESmytable
FFPEP7up05/02/201810PEP
FFCOCccz01/05/20186COC
FFNESnesg30/08/20186NESnesg123
RPEPmir15/03/20188PEPmirhelpersupplierproduct30/04/201825/08/201828/09/2018
RCOCspr30/06/20186COCsprrow 10COCCOC565
RCOCcoca15/07/20186COCCOCfanCOCfan788
RNESnese29/09/20183NESCOCsprCOCspr667
RNESnesa31/10/20183NESNESNES423
GSCOCspr13/03/20186COCsprNESnesNESnes323
GSPEPmir23/08/20188PEPmirNESnesgNESnesg566
GSNESneso15/11/201812NESnesoNESnesoNESneso101012
PEPPEP10911
PEPmirPEPmir889
mytable2
01/01/20181
01/05/20182
29/09/20183
K10 (COC)=L10&M1031/12/20183
COC under helper1 header=IF(ISERROR(MATCH(C2,$M$10:$M$18,0)),B2&"",B2&C2)
can you see any inaccuracies ?

<colgroup><col span="3"><col><col span="9"><col span="3"><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0
Thank you guys,
I owe you a beer :).

I tried script and it works.
I will also try oldbrewer solution and choose which one is best for me.

Thank you for your time!
(y)
 
Upvote 0
it keeps my brain cells from atrophying.........
:ROFLMAO:
I still couldnt do job with these formulas, I struggle with helper1, I made somewhere mistake, I got only supplier result.
And also I dont know how to get discount number which should be linked with date.
Possible to get that excel file if you have it to explore formulas and see where I made mistake?

Thank you ;)
 
Upvote 0
If your happy to use some code, try this for results in column "F".
Code:
[COLOR=Navy]Sub[/COLOR] MG08Dec53
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, n [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] Txt [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("H3"), Range("H" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False

[COLOR=Navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    Txt = Dn.Value & Dn.Offset(, 1).Value
    [COLOR=Navy]Set[/COLOR] .Item(Txt) = Dn
[COLOR=Navy]Next[/COLOR]

[COLOR=Navy]Set[/COLOR] Rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
Txt = ""
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
  [COLOR=Navy]For[/COLOR] n = 0 To 1
   Txt = IIf(n = 0, Dn.Value & Dn.Offset(, 1).Value, Dn.Value)
        [COLOR=Navy]If[/COLOR] .exists(Txt) [COLOR=Navy]Then[/COLOR]
           [COLOR=Navy]Select[/COLOR] [COLOR=Navy]Case[/COLOR] True
                [COLOR=Navy]Case[/COLOR] Dn.Offset(, 2).Value > Range("L2").Value
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "L"), "0.00%")
                
                [COLOR=Navy]Case[/COLOR] Dn.Offset(, 2).Value <= Range("L2") _
                And Dn.Offset(, 2).Value > Range("K2")
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "L"), "0.00%")
            
                [COLOR=Navy]Case[/COLOR] Dn.Offset(, 2).Value <= Range("K2") _
                And Dn.Offset(, 2).Value > Range("J2")
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "K"), "0.00%")

                [COLOR=Navy]Case[/COLOR] Dn.Offset(, 2).Value <= Range("J2").Value
                Dn.Offset(, 4).Value = Format(Cells(.Item(Txt).Row, "J"), "0.00%")
           [COLOR=Navy]End[/COLOR] Select
           [COLOR=Navy]Exit[/COLOR] For
        [COLOR=Navy]End[/COLOR] If
  [COLOR=Navy]Next[/COLOR] n
[COLOR=Navy]Next[/COLOR] Dn

[COLOR=Navy]End[/COLOR] With
Application.ScreenUpdating = True
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
Hi MickG,
when I change this VB and apply my real field numbers (as they are different, some of them are not on same sheet), I get Runtime error `13`: type mismatch on line: "Txt = Dn.Value & Dn.Offset(, 1).Value".
Since I dont know anything about VB codes, could you explain where I should search for mistake?
Thank you.
 
Upvote 0
I assume the format of the test data and actual data is the same
The code you have will only look at the active sheet, this can be changed ,but that is not your present problem .!!

Is it possible to show an example of the data that fails. If you can't post on forum you can use "Box.com" or "DropBox.com" to send an example file. "Please send excel file not a Picture"
 
Upvote 0
I assume the format of the test data and actual data is the same
The code you have will only look at the active sheet, this can be changed ,but that is not your present problem .!!

Is it possible to show an example of the data that fails. If you can't post on forum you can use "Box.com" or "DropBox.com" to send an example file. "Please send excel file not a Picture"
Here is the whole file for which I am struggling. I tried to change fields to pick up values from another sheet, but I got stuck with VB script.
Ignore hidden rows, because I am getting this kind of report from software and they are not important for this part of job, but they will be always in this report.
And which value to change in VB script when I want to move "Discount" results (if I need them in another row), since I couldnt find it anywhere in script something which looks like defined row?
https://www.dropbox.com/s/682ysf0qglvoed6/Report.xlsx?dl=0

Ty
 
Upvote 0
i HAVE SUPPLIED THE FORMULA FOR HELPER 1 WHICH HAS TO BE DRAGGED DOWN. I am finding eg cocacola plus sprite or cocacola with no product specified. I used helper 2 table to identify the date offset.............
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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