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
 
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 ?
the 5 in E2 comes from
=OFFSET($K$9,MATCH(G2,$K$10:$K$18,0),VLOOKUP(D2,mytable2,2)+2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

<colgroup><col span="3"><col><col span="9"><col span="3"><col></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this Based on your data sheet:-
Results column "U" sheet "Database"
NB:- The date in column "AG" of sheet "Rabat", I think should read "1/1/2019" ???
NB:- I note that you now have 4 columns in sheet "Rabat", of Dates/Percentages. The code should now cover any number of Extra columns of these dates/Percentages.
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Dec53
[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] RngAc [COLOR="Navy"]As[/COLOR] Range, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] R [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ray() [COLOR="Navy"]As[/COLOR] Variant, Dic [COLOR="Navy"]As[/COLOR] Object
[COLOR="Navy"]With[/COLOR] Sheets("Rabat")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range("A4", .Range("A" & Rows.Count).End(xlUp))
    [COLOR="Navy"]Set[/COLOR] RngAc = .Range("L3", .Cells(3, Columns.Count).End(xlToLeft)).SpecialCells(xlCellTypeConstants)
[COLOR="Navy"]End[/COLOR] With
MsgBox RngAc.Address
ReDim Ray(1 To RngAc.Count, 1 To 2)
   [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] RngAc
    [COLOR="Navy"]If[/COLOR] IsDate(R.Value) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        [COLOR="Navy"]Set[/COLOR] Ray(c, 1) = R
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] R
Application.ScreenUpdating = False

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

[COLOR="Navy"]With[/COLOR] Sheets("Database")
[COLOR="Navy"]Set[/COLOR] Rng = .Range("B6", .Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
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, Trim(Dn.Value) & Trim(Dn.Offset(, 10).Value), Trim(Dn.Value))
        [COLOR="Navy"]With[/COLOR] Sheets("Rabat")
        [COLOR="Navy"]If[/COLOR] Dic.exists(Txt) [COLOR="Navy"]Then[/COLOR]
           [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray)
             [COLOR="Navy"]If[/COLOR] Ray(Ac, 1) = Ray(1, 1) [COLOR="Navy"]Then[/COLOR]
                 [COLOR="Navy"]If[/COLOR] Dn.Offset(, 13).Value <= CDate(Ray(Ac, 1)) [COLOR="Navy"]Then[/COLOR]
                   Dn.Offset(, 19).Value = Format(.Cells(Dic(Txt).Row, Ray(Ac, 1).Column), "0.00%")
                 [COLOR="Navy"]End[/COLOR] If
             [COLOR="Navy"]ElseIf[/COLOR] CDate(Ray(Ac, 1)) = CDate(Ray(UBound(Ray, 1), 1)) [COLOR="Navy"]Then[/COLOR]
                 [COLOR="Navy"]If[/COLOR] Dn.Offset(, 13).Value > CDate(Ray(Ac, 1)) [COLOR="Navy"]Then[/COLOR]
                    Dn.Offset(, 19).Value = Format(.Cells(Dic(Txt).Row, Ray(Ac, 1).Column), "0.00%")
                 [COLOR="Navy"]End[/COLOR] If
             [COLOR="Navy"]Else[/COLOR]
                [COLOR="Navy"]If[/COLOR] Dn.Offset(, 13).Value <= CDate(Ray(Ac, 1)) _
                  And Dn.Offset(, 13).Value > CDate(Ray(Ac - 1, 1)) [COLOR="Navy"]Then[/COLOR]
                  Dn.Offset(, 19).Value = Format(.Cells(Dic(Txt).Row, Ray(Ac, 1).Column), "0.00%")
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]End[/COLOR] If
         
        [COLOR="Navy"]Next[/COLOR] Ac
   [COLOR="Navy"]Exit[/COLOR] For
    [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Dn
Application.ScreenUpdating = True
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[/TABLE]
I got this message when I try to put formula under helper1 header:
Thank you oldbrewer, I fix it, just instead "," i put ";", since we have different versions.
Thank you, it works (y)(y)
 
Upvote 0
there are always a few ways to achieve your aim, and different versions and date formats always complicate things..........
 
Upvote 0
there are always a few ways to achieve your aim, and different versions and date formats always complicate things..........
Can you see any mistake in formula, since I am getting "NAME" error?
Everything works OK except E row (discount percentages).
Can you see any mistake in this formula?
X58wRze.png
 
Upvote 0
have you named the lower table as mytable2
if you think you have use insert name , mytable2, ok then delete it then rename it
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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