VBA Excel 2组合问题



我正在尝试制作一个应用程序,使您可以使用两个组合蛋白更新销售条件详细信息。

有关演示的此屏幕截图:

1)数据表

2)此用户形式涉及创建新的销售条件

3)需要第二个用户形式来修改数据并在所需的工作表中进行更新

关于我创建新销售条件的源代码,您可以在此处找到它:

Private Sub bAnnuler_Click()
    Unload Me 
End Sub
Private Sub bEnregistrer_Click()
   Sheets("ConditionsVente").Activate
   Range("A1").Select
   Selection.End(xlDown).Select  'On se positionne sur la derniere ligne non  vide
   Selection.Offset(1, 0).Select 'On se décale d'une ligne vers le bas
  'ActiveCell = txtNom.Value
  ActiveCell.Offset(0, 3).Value = txtPrix
  ActiveCell.Offset(0, 4).Value = txtDélai
End Sub
Private Sub bReinitialiser_Click()
  txtPrix = ""
  txtDélai = ""
End Sub

Private Sub cboFournisseur_Change()
End Sub
Private Sub UserForm_Initialize()
  'initialiser combobox fournisseur
  Dim Fournisseurs As Range
  Dim Matieres As Range
  Set Fournisseurs = Worksheets("Fournisseurs").Range("A2:A" &  Worksheets("Fournisseurs").Range("A2").End(xlDown).Row)
  Me.cboFournisseur.MaxLength = Fournisseurs.Count
  Me.cboFournisseur.List = Fournisseurs.Value
  'initialiser combobox matiere
  Set Matieres = Worksheets("Matieres").Range("A2:A" &      Worksheets("Matieres").Range("A2").End(xlDown).Row)
  Me.cboMatiere.MaxLength = Matieres.Count
  Me.cboMatiere.List = Matieres.Value
End Sub

我有两个问题:1)当我运行此代码时,我创建了一个新的销售条件,但是表中保存的只是价格(法语中的prix)和延迟(法语中的délai)以及供应商的列(法语中的Fournisseurs)和原材料(法语的Matiere)仍然是空的。

2)第二点为了制作一个用户形式,让我在所需表中修改销售条件,最简单的方法是什么?

对于第1部分,您需要此:

Private Sub bEnregistrer_Click()
   Dim nextRow as Integer
   With Worksheets("ConditionsVente")
       nextRow = .Range("A1").end(xlDown).Row + 1
       .Range("A" & nextRow) = txtNom.Value
       .Range("B" & nextRow) = txtMatiere.Value
       .Range("C" & nextRow) = txtPrix
       .Range("D" & nextRow) = txtDélai
   End With
End Sub

第2部分尝试以下方法:

Private Sub btnSave_Click()
  Dim Fournisseurs As Range, Fournisseur as range
  Set Fournisseurs = Worksheets("Fournisseurs").Range("A2:A" &  Worksheets("Fournisseurs").Range("A2").End(xlDown).Row)
  For each Fournisseur in Fournisseurs
       If Fournisseur = txtNom.Value And Fournisseur.offset(0, 1) = txtMatiere.Value Then
           Fournisseur.offset(0, 3) = txtPrix
           Fournisseur.offset(0, 3) = txtDélai
       End if
  Next Fournisseur    
End Sub

最新更新