Bonjour à Tous,
Voilà un bon moment que j'essaye de comprendre pourquoi ce message d'erreur "Run time error 13" qui indique un "type mismatch"
L'erreur se produit lors du chargement d'une variable tableau. Celle-ci est déclarée en tant que Variant. Les valeurs chargées dans le tableau sont des valeurs numériques et du texte.
Le début du code est le suivant,
Sub calc_Prix()
'definition des variables
Dim wb As Workbook
Set wb = Workbooks("Catalogue_Reference.xlsm")
Dim feuille_matrice As Worksheet
Set feuille_matrice = wb.Worksheets("Matrice_reference")
Dim Prix As Worksheet
Set Prix = wb.Worksheets("Prix")
Dim der_lig As Long
Dim der_col As Long
Dim matrice As Range
der_lig = feuille_matrice.Range("A" & Rows.Count).End(xlUp).Row
der_col = feuille_matrice.Range("A1").End(xlToRight).Column
feuille_matrice.Activate
Set matrice = feuille_matrice.Range(Cells(1, 1), Cells(der_lig, der_col))
Dim var_gamme, var_ssgamme, var_ref, var_desig As String
'CU=cout unitaire HT
Dim CU_ref As Currency
Dim CU_etiq As Currency
Dim CU_emb1 As Currency
Dim CU_emb2 As Currency
Dim CU_transp1 As Currency
Dim CU_transp2 As Currency
Dim CU_acc As Currency
Dim CU_comp As Currency
Dim CU_market As Currency
Dim K As Single 'K= coeff appliqué sur cout complet pour obtenir le prix
Dim TVA_A As Single
Dim TVA_B As Single
Dim TVA_C As Single
'TVA_A à 5,5% sur produits alimentaires 1ere nécessité
'TVA_B à 20% sur produits alimentaires hors 1ere nécessité
'TVA_C 'TVA à 20% sur produits non alimentaires
TVA_A = 5.5 / 100
TVA_B = 20 / 100
TVA_C = 20 / 100
Sheets("Scenario").Activate
Dim der_lig_S, der_col_S, pre_lig_S, pre_col_S As Long
der_lig_S = Sheets("Scenario").Range("D" & Rows.Count).End(xlUp).Row
der_col_S = Sheets("Scenario").Cells(2, Columns.Count).End(xlToLeft).Column
pre_lig_S = Sheets("Scenario").Range("D1").End(xlDown).Row
pre_col_S = Sheets("Scenario").Range("A2").End(xlToRight).Column
Dim plage_S As Range
Set plage_S = Sheets("Scenario").Range(Cells(pre_lig_S, pre_col_S), Cells(der_lig_S, der_col_S))
Dim tableau() As Variant
ReDim tableau(der_lig_S - 1, der_col_S - 1)
For i = 0 To der_lig_S - 2
For j = 0 To der_col_S - 2
tableau(i, j) = plage_S.Cells(i + 1, j + 1)
VarType (tableau(i, j))
Next j
Next i
Prix.Activate
Prix.Cells.ClearContents
Prix.Cells.ClearFormats
Dim range1, range2 As Range
feuille_matrice.Activate
Set range1 = matrice.Range(Cells(1, 1), Cells(der_lig, 4))
Set range2 = matrice.Range(Cells(1, 21), Cells(der_lig, 21))
range1.Copy Destination:=Prix.Cells(1, 1)
Dim der_col_P As Long 'derniere colonne dans feuille Prix
der_col_P = Prix.Cells(1, Columns.Count).End(xlToLeft).Column
range2.Copy Destination:=Prix.Cells(1, der_col_P + 1)
Dim der_lig_P As Long
Prix.Activate
Prix.Cells.Interior.ColorIndex = xlColorIndexNone
der_lig_P = Prix.Cells(Rows.Count, 1).End(xlUp).Row
der_col_P = Prix.Cells(1, Columns.Count).End(xlToLeft).Column
Cells(1, der_col_P + 1) = "CU_etiq"
Cells(1, der_col_P + 2) = "CU_emb1"
Cells(1, der_col_P + 3) = "CU_emb2"
Cells(1, der_col_P + 4) = "CU_transp1"
Cells(1, der_col_P + 5) = "CU_transp2"
Cells(1, der_col_P + 6) = "CU_market"
Cells(1, der_col_P + 7) = "Coeff_prix"
Dim libelleScenario As Integer
libelleScenario = InputBox("entrer n°scenario")
Select Case libelleScenario
Case Is = 1
CU_etiq = tableau(1, 4)
CU_emb1 = tableau(1, 5)
CU_emb2 = tableau(1, 6)
CU_transp1 = tableau(1, 7)
CU_transp2 = tableau(1, 8)
CU_market = tableau(1, 9)
K = tableau(1, 10)
Case Is = 2
CU_etiq = tableau(2, 4)
CU_emb1 = tableau(2, 5)
CU_emb2 = tableau(2, 6)
CU_transp1 = tableau(2, 7)
CU_transp2 = tableau(2, 8)
CU_market = tableau(2, 9)
K = tableau(2, 10)
Case Is = 3
CU_etiq = tableau(3, 4)
CU_emb1 = tableau(3, 5)
CU_emb2 = tableau(3, 6)
CU_transp1 = tableau(3, 7)
CU_transp2 = tableau(3, 8)
CU_market = tableau(3, 9)
K = tableau(3, 10)
Case Is = 4
CU_etiq = tableau(4, 4)
CU_emb1 = tableau(4, 5)
CU_emb2 = tableau(4, 6)
CU_transp1 = tableau(4, 7)
CU_transp2 = tableau(4, 8)
CU_market = tableau(4, 9)
K = tableau(4, 10)
Case Is = 5
CU_etiq = tableau(5, 4)
CU_emb1 = tableau(5, 5)
CU_emb2 = tableau(5, 6)
CU_transp1 = tableau(5, 7)
CU_transp2 = tableau(5, 8)
CU_market = tableau(5, 9)
K = tableau(5, 10)
Case Is = 6
CU_etiq = tableau(6, 4)
CU_emb1 = tableau(6, 5)
CU_emb2 = tableau(6, 6)
CU_transp1 = tableau(6, 7)
CU_transp2 = tableau(6, 8)
CU_market = tableau(6, 9)
K = tableau(6, 10)
Case Is = 7
CU_etiq = tableau(7, 4)
CU_emb1 = tableau(7, 5)
CU_emb2 = tableau(7, 6)
CU_transp1 = tableau(7, 7)
CU_transp2 = tableau(7, 8)
CU_market = tableau(7, 9)
K = tableau(7, 10)
End Select
Si vous pouvez m'aider à comprendre la raison du plantage, je suis preneur....
Merci de votre aide,
Voilà un bon moment que j'essaye de comprendre pourquoi ce message d'erreur "Run time error 13" qui indique un "type mismatch"
L'erreur se produit lors du chargement d'une variable tableau. Celle-ci est déclarée en tant que Variant. Les valeurs chargées dans le tableau sont des valeurs numériques et du texte.
Le début du code est le suivant,
Sub calc_Prix()
'definition des variables
Dim wb As Workbook
Set wb = Workbooks("Catalogue_Reference.xlsm")
Dim feuille_matrice As Worksheet
Set feuille_matrice = wb.Worksheets("Matrice_reference")
Dim Prix As Worksheet
Set Prix = wb.Worksheets("Prix")
Dim der_lig As Long
Dim der_col As Long
Dim matrice As Range
der_lig = feuille_matrice.Range("A" & Rows.Count).End(xlUp).Row
der_col = feuille_matrice.Range("A1").End(xlToRight).Column
feuille_matrice.Activate
Set matrice = feuille_matrice.Range(Cells(1, 1), Cells(der_lig, der_col))
Dim var_gamme, var_ssgamme, var_ref, var_desig As String
'CU=cout unitaire HT
Dim CU_ref As Currency
Dim CU_etiq As Currency
Dim CU_emb1 As Currency
Dim CU_emb2 As Currency
Dim CU_transp1 As Currency
Dim CU_transp2 As Currency
Dim CU_acc As Currency
Dim CU_comp As Currency
Dim CU_market As Currency
Dim K As Single 'K= coeff appliqué sur cout complet pour obtenir le prix
Dim TVA_A As Single
Dim TVA_B As Single
Dim TVA_C As Single
'TVA_A à 5,5% sur produits alimentaires 1ere nécessité
'TVA_B à 20% sur produits alimentaires hors 1ere nécessité
'TVA_C 'TVA à 20% sur produits non alimentaires
TVA_A = 5.5 / 100
TVA_B = 20 / 100
TVA_C = 20 / 100
Sheets("Scenario").Activate
Dim der_lig_S, der_col_S, pre_lig_S, pre_col_S As Long
der_lig_S = Sheets("Scenario").Range("D" & Rows.Count).End(xlUp).Row
der_col_S = Sheets("Scenario").Cells(2, Columns.Count).End(xlToLeft).Column
pre_lig_S = Sheets("Scenario").Range("D1").End(xlDown).Row
pre_col_S = Sheets("Scenario").Range("A2").End(xlToRight).Column
Dim plage_S As Range
Set plage_S = Sheets("Scenario").Range(Cells(pre_lig_S, pre_col_S), Cells(der_lig_S, der_col_S))
Dim tableau() As Variant
ReDim tableau(der_lig_S - 1, der_col_S - 1)
For i = 0 To der_lig_S - 2
For j = 0 To der_col_S - 2
tableau(i, j) = plage_S.Cells(i + 1, j + 1)
VarType (tableau(i, j))
Next j
Next i
Prix.Activate
Prix.Cells.ClearContents
Prix.Cells.ClearFormats
Dim range1, range2 As Range
feuille_matrice.Activate
Set range1 = matrice.Range(Cells(1, 1), Cells(der_lig, 4))
Set range2 = matrice.Range(Cells(1, 21), Cells(der_lig, 21))
range1.Copy Destination:=Prix.Cells(1, 1)
Dim der_col_P As Long 'derniere colonne dans feuille Prix
der_col_P = Prix.Cells(1, Columns.Count).End(xlToLeft).Column
range2.Copy Destination:=Prix.Cells(1, der_col_P + 1)
Dim der_lig_P As Long
Prix.Activate
Prix.Cells.Interior.ColorIndex = xlColorIndexNone
der_lig_P = Prix.Cells(Rows.Count, 1).End(xlUp).Row
der_col_P = Prix.Cells(1, Columns.Count).End(xlToLeft).Column
Cells(1, der_col_P + 1) = "CU_etiq"
Cells(1, der_col_P + 2) = "CU_emb1"
Cells(1, der_col_P + 3) = "CU_emb2"
Cells(1, der_col_P + 4) = "CU_transp1"
Cells(1, der_col_P + 5) = "CU_transp2"
Cells(1, der_col_P + 6) = "CU_market"
Cells(1, der_col_P + 7) = "Coeff_prix"
Dim libelleScenario As Integer
libelleScenario = InputBox("entrer n°scenario")
Select Case libelleScenario
Case Is = 1
CU_etiq = tableau(1, 4)
CU_emb1 = tableau(1, 5)
CU_emb2 = tableau(1, 6)
CU_transp1 = tableau(1, 7)
CU_transp2 = tableau(1, 8)
CU_market = tableau(1, 9)
K = tableau(1, 10)
Case Is = 2
CU_etiq = tableau(2, 4)
CU_emb1 = tableau(2, 5)
CU_emb2 = tableau(2, 6)
CU_transp1 = tableau(2, 7)
CU_transp2 = tableau(2, 8)
CU_market = tableau(2, 9)
K = tableau(2, 10)
Case Is = 3
CU_etiq = tableau(3, 4)
CU_emb1 = tableau(3, 5)
CU_emb2 = tableau(3, 6)
CU_transp1 = tableau(3, 7)
CU_transp2 = tableau(3, 8)
CU_market = tableau(3, 9)
K = tableau(3, 10)
Case Is = 4
CU_etiq = tableau(4, 4)
CU_emb1 = tableau(4, 5)
CU_emb2 = tableau(4, 6)
CU_transp1 = tableau(4, 7)
CU_transp2 = tableau(4, 8)
CU_market = tableau(4, 9)
K = tableau(4, 10)
Case Is = 5
CU_etiq = tableau(5, 4)
CU_emb1 = tableau(5, 5)
CU_emb2 = tableau(5, 6)
CU_transp1 = tableau(5, 7)
CU_transp2 = tableau(5, 8)
CU_market = tableau(5, 9)
K = tableau(5, 10)
Case Is = 6
CU_etiq = tableau(6, 4)
CU_emb1 = tableau(6, 5)
CU_emb2 = tableau(6, 6)
CU_transp1 = tableau(6, 7)
CU_transp2 = tableau(6, 8)
CU_market = tableau(6, 9)
K = tableau(6, 10)
Case Is = 7
CU_etiq = tableau(7, 4)
CU_emb1 = tableau(7, 5)
CU_emb2 = tableau(7, 6)
CU_transp1 = tableau(7, 7)
CU_transp2 = tableau(7, 8)
CU_market = tableau(7, 9)
K = tableau(7, 10)
End Select
Si vous pouvez m'aider à comprendre la raison du plantage, je suis preneur....
Merci de votre aide,