2016-12-23 2 views
1

두 개의 콤보 상자를 사용하여 판매 조건 세부 정보를 업데이트 할 수있는 응용 프로그램을 만들려고합니다.VBA Excel 2 combobox 문제

데모이 스크린 샷을 참조하십시오

1) Datasheet

2)이 Userform 두 번째 정의 폼이 데이터를 수정하는 데 필요한 새로운 판매 조건

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 

나는이 코드를 실행할 때 새로운 판매 조건을 만들지 만 시트에 저장되는 내용은 가격 (프랑스어)과 지연 (프랑스어)이며 공급 업체 (Fournisseurs in french) 및 원료 (Matiere in french)의 열은 여전히 ​​비어 있습니다.

2) 두 번째 요점은 원하는 시트의 판매 조건을 수정할 수있는 사용자 정의를 만들기 위해서 무엇을 가장 간단하게 실현할 수 있습니까? 제 2 부

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 

이 시도 :

+0

은 아래를 참조 - 일반적으로는 사용하지 않아야합니다'Activate' 및 코드에서'Select'. 그것은 정말로 필요하지 않습니다. –

답변

1

1 부이 필요

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 
+0

그것은 두 번째 부분에 대 한 알렉스 P – zakaria

+0

대단히 고마워, 판매 조건을 수정하려면 comboboxes의 두 데이터를 먼저 존재해야합니다 설명하는 조건을 추가해야합니까? 너는 어떤 생각이있어? – zakaria

+0

4 인 이상 루프를 만들고 매치 매치를 확인하십시오. 예 : 범위 ("a"& row) = "헤르메스"AND 범위 ("a"& 행) .offset (0,1) = "matiere2"... –