我试图搜索一个包含很多案例的大表并为其返回一个值[我已尝试过Index / Match和Vlookup,但由于市场变量有很多不同,我可以&# 39;让它工作]
模板链接enter link description here
这是主输入Excel表。该表中的重要因素是"客户ID,货币,市场" (由用户输入)。
使用这三个变量,我想搜索这个列表,并在主输入表中返回MIN值。 正如您所看到的,在某些情况下,有2/3的变量是相同的。
Option Explicit
Sub komisijas_calc_Click()
'Declare the variables
Dim klienta_nr As Long
Dim ISIN As String
Dim Cena As Double
Dim Skaits As Double
Dim Komisija As Double
Dim vk As String
Dim Summa As Double
Dim kSheet As Worksheet
Dim lngFirstRow As Long: lngFirstRow = 2
Dim lngLastRow As Long
Dim lngCol As Long: lngCol = 2
Dim lngCounter As Long
Dim lngKom As Long: lngKom = 11
Set kSheet = ThisWorkbook.Sheets("spec_klienti")
With Worksheets(1)
lngLastRow = .Cells(.Rows.Count, lngCol).End(xlUp).Row
For lngCounter = lngFirstRow To lngLastRow
klienta_nr = Range("B" & lngCounter).Value
ISIN = Range("E" & lngCounter).Value
Cena = Range("H" & lngCounter).Value
Skaits = Range("I" & lngCounter).Value
vk = Range("D" & lngCounter).Value
Summa = Cena * Skaits
Select Case klienta_nr
Case 1
'(Vācija, Francija, Nīderlandes, Itālija, Īrija) - 30 EUR MIN
If klienta_nr = 1 And (Left(ISIN, 2) = "DE" Or Left(ISIN, 2) = "FR" Or Left(ISIN, 2) = "NL" Or Left(ISIN, 2) = "IT" Or Left(ISIN, 2) = "IE") Then
Komisija = Summa * 0.01
.Cells(lngCounter, lngKom) = Komisija
End If
If klienta_nr = 636092 And Komisija <= 30 Then
.Cells(lngCounter, lngKom) = 30
End If
If klienta_nr = 1 And (Left(ISIN, 2) <> "DE" Or Left(ISIN, 2) <> "FR" Or Left(ISIN, 2) <> "NL" Or Left(ISIN, 2) <> "IT" Or Left(ISIN, 2) <> "IE") Then
Komisija = Summa * 0.003
If Komisija >= 40 Then
.Cells(lngCounter, lngKom) = 40
End If
End If
Case 2
'(Vācija, Francija, Nīderlandes, Itālija, Īrija) - 30 EUR MIN
If klienta_nr = 2 And (Left(ISIN, 2) = "DE" Or Left(ISIN, 2) = "FR" Or Left(ISIN, 2) = "NL" Or Left(ISIN, 2) = "IT" Or Left(ISIN, 2) = "IE") Then
Komisija = Summa * 0.01
.Cells(lngCounter, lngKom) = Komisija
End If
'Set 30 EUR Min
If klienta_nr = 2 And Komisija <= 30 Then
.Cells(lngCounter, lngKom) = 30
End If
If klienta_nr = 2 And (Left(ISIN, 2) <> "DE" Or Left(ISIN, 2) <> "FR" Or Left(ISIN, 2) <> "NL" Or Left(ISIN, 2) <> "IT" Or Left(ISIN, 2) <> "IE") Then
GoTo AllElseFails
End If
Case Else
AllElseFails:
'IP2, 0.03% komisija, 40 EUR/USD Max
If Right(vk, 1) = 1 Or Right(vk, 1) = 8 Then
Komisija = Summa * 0.003
.Cells(lngCounter, lngKom) = Komisija
End If
'IP1, 0.1% komisija, 40 EUR/USD Max
If Right(vk, 1) = 7 Then
Komisija = Summa * 0.01
.Cells(lngCounter, lngKom) = Komisija
End If
'Komisija MAX is 40, so anything >=40 equals 40
If Komisija >= 40 Then
.Cells(lngCounter, lngKom) = 40
End If
'End If
End Select
Next lngCounter
End With
End Sub