@Hugo
Lis d'abord mon post précédent de 10:11.
ce post est pour montrer tout le code VBA du classeur Excel.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
code VBA de Module1 (46 lignes) :
Option Explicit: Option Base 1
Public Const LC As String * 14 = "Local Currency": Dim T2, m&, n&
Private Sub Init()
Dim T1, k As Byte, d&, i&: m = Rows.Count
T1 = Application.Transpose(Worksheets("FX rates").[C2:C7])
With Worksheets("db")
Application.ScreenUpdating = 0: .AutoFilterMode = 0
n = .Cells(m, 2).End(3).Row: If n = 1 Then Exit Sub
T2 = .Range("A2:E" & n): n = n - 1
End With
For i = 1 To n
Select Case T2(i, 1)
Case "KWD": k = 1: Case "AED": k = 2: Case "BHD": k = 3: Case "QAR": k = 4
Case "SAR": k = 5: Case "USD": k = 6: Case Else: k = 0
End Select
If k > 0 Then If T1(k) > 0 Then T2(i, 5) = T2(i, 4) / T1(k)
Next i
Worksheets("Output").Select: d = Cells(m, 2).End(3).Row
If d > 4 Then Rows("5:" & d).Delete
End Sub
Sub DoTbl()
Dim TH@(3, 13), F@, G@, v@, x@, a$, b$, d$, r&, c As Byte, p As Byte, k As Byte, i&: Init
If [C2] = "" Then Application.EnableEvents = 0: [C2] = LC: Application.EnableEvents = -1
a = T2(1, 2): p = InStr(a, "_"): a = Left$(a, p - 1): m = 1: r = 5: c = 3: k = 5 + (Asc([C2]) = 76)
For i = 1 To n
d = T2(i, 2): b = d: p = InStr(b, "_"): b = Left$(b, p - 1)
If b <> a Then
Cells(r, 2) = "Total Market " & m: Cells(r, 2).Resize(, 14).Font.Bold = -1
For p = 1 To 13
Cells(r, p + 2) = TH(1, p): TH(3, p) = TH(3, p) + TH(2, p): TH(1, p) = 0: TH(2, p) = 0
Next p
r = r + 1: a = b: m = m + 1
End If
Cells(r, 2) = d: v = T2(i, k): x = T2(i, 5): Cells(r, c) = v: p = c - 2
TH(1, p) = TH(1, p) + v: TH(2, p) = TH(2, p) + x: F = F + v: G = G + x: c = c + 1
If c = 15 Then
TH(1, 13) = TH(1, 13) + F: TH(2, 13) = TH(2, 13) + G: Cells(r, c) = F: F = 0: G = 0: r = r + 1: c = 3
End If
Next i
Cells(r, 2) = "Total Market " & m: Cells(r, 2).Resize(2, 14).Font.Bold = -1: i = r + 1
For p = 1 To 13: Cells(r, p + 2) = TH(1, p): TH(3, p) = TH(3, p) + TH(2, p): Cells(i, p + 2) = TH(3, p): Next p
Cells(i, 2) = "Total Zone (€)": Range("C5:O" & i).NumberFormat = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
code VBA de Module2 (7 lignes) :
Option Explicit
Sub Devise()
If ActiveSheet.Name <> "Output" Then Exit Sub
If [C2] = "" Then [C2] = LC Else [C2] = IIf([C2] = LC, "Euro", LC)
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
code VBA du module de la feuille "Output" (7 lignes) :
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .CountLarge > 1 Then Exit Sub
If .Address = "$C$2" Then DoTbl
End With
End Sub
rhodo