اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

لا يكتمل عملية بحث عن رقم فاتورة فى الفورم


الردود الموصى بها

السلام عليكم ورحمة الله وبركاتة

شرح بالتفصيل لعملية البحث عن رقم فاتورة وعرض البيانات المرتبطة بها في

VBA Excel

فهم المطلوب
نريد أن نقوم بإنشاء نموذج في Excel VBA حيث:
 * TextBox2: لإدخال رقم الفاتورة للبحث عنه.
 * TextBox5: لعرض تاريخ الفاتورة بعد البحث.
 * ComboBox1: لعرض اسم المخزن المحول منه بعد البحث.
* ComboBox2: لعرض اسم المخزن المحول الية بعد البحث.
* ListBox1: لعرض تفاصيل المنتج (كود، اسم، كمية) لكل منتج في الفاتورة.
خطوات التنفيذ
1. تصميم UserForm:
 * قم بإنشاء UserForm جديد في Excel VBA.
 * أضف عناصر التحكم التالية:
* TextBox2: لإدخال رقم الفاتورة.
* TextBox5: لعرض تاريخ الفاتورة.
 * ComboBox1: لعرض اسم المخزن المحول منه
* ComboBox2: لعرض اسم المخزن المحول الية
* ListBox1: لعرض تفاصيل المنتجات.
* CommandButton1: لتنفيذ عملية البحث.
2. إعداد البيانات في ورقة العمل:
 * افترض أن لدينا ورقة عمل باسم "Transferts" تحتوي على الأعمدة التالية:
   * رقم الفاتورة
   * تاريخ الفاتورة
   * اسم المخزن المحول منه
   * اسم المخزن المحول الية
   * كود المنتج
   * اسم المنتج
   * الكمية
تم عمل المطلوب
ولاكن عند الاستعلام عن الفاتورة
لايتم عرض البيانات فى
 ComboBox1: لعرض اسم المخزن المحول منه
 ComboBox2: لعرض اسم المخزن المحول الية
ويكتفى بعرض البيانات فى listbox1
فقط

 

 

 

Private Sub Search_Click()
Dim ws As Worksheet
    Dim LastRow As Long
    Dim i As Long
    Dim ii As Long
    Dim searchValue As String
    Set ws = ThisWorkbook.Sheets("Transferts") ' اسم ورقة العمل
    LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
    searchValue = TextBox2.Value
    ' مسح قوائم قبل عملية البحث
   ListBox1.Clear
   ComboBox1.Clear
   ComboBox2.Clear
   ComboBox3.Clear
   ComboBox4.Clear
   TextBox1 = ""

    For i = 2 To LastRow
        If ws.Cells(i, 1).Value = searchValue Then ' البحث عن رقم الفاتورة
            TextBox5.Value = ws.Cells(i, 2).Value ' عرض التاريخ
            If ComboBox1.ListCount = 0 Then
                ComboBox1.AddItem ws.Cells(i, 4).Value ' عرض اسم المخزن المحول منة
                ComboBox2.AddItem ws.Cells(i, 5).Value ' عرض اسم المخزن المحول الية
            End If
            'ListBox1.AddItem ws.Cells(i, 6).Value & " - " & ws.Cells(i, 7).Value & " - " & ws.Cells(i, 8).Value
            Me.ListBox1.AddItem ws.Cells(i, 6) ' عرض كود الصنف
            Me.ListBox1.List(ListBox1.ListCount - 1, 1) = ws.Cells(i, 7) ' عرض اسم الصنف
            Me.ListBox1.List(ListBox1.ListCount - 1, 2) = ws.Cells(i, 8) ' عرض الكمية
        End If
        Next i
             Me.ListBox1.ColumnCount = 4
             Me.ListBox1.ColumnWidths = "130;130;55"
End Sub



'المشكلة فى الكود هذا
'If ComboBox1.ListCount = 0 Then
            '    ComboBox1.AddItem ws.Cells(i, 4).Value ' عرض اسم المخزن المحول منة
             '   ComboBox2.AddItem ws.Cells(i, 5).Value ' عرض اسم المخزن المحول الية
           ' End If

 

 

 

 

 

 

Copy of امين مخزن.xlsm

تم تعديل بواسطه mahmoud nasr alhasany
رابط هذا التعليق
شارك

  • mahmoud nasr alhasany changed the title to لا يكتمل عملية بحث عن رقم فاتورة فى الفورم
7 ساعات مضت, mahmoud nasr alhasany said:
'تم حل المشكلة فى الكود هذا
'If ComboBox1.ListCount = 0 Then
            '    ComboBox1 = ws.Cells(i, 4).Value ' عرض اسم المخزن المحول منة
             '   ComboBox2 = ws.Cells(i, 5).Value ' عرض اسم المخزن المحول الية
           ' End If

 

 

 

تم تعديل بواسطه mahmoud nasr alhasany
رابط هذا التعليق
شارك

بخصوص التعديل لم يتم حل المشكلة

Private Sub CommandButton2_Click()
    '   ' ... your existing code ...
'
'    ' Data validation
'    If Not IsNumeric(TextBox1.Value) Then
'        MsgBox "Quantity must be a number."
'        Exit Sub
'    End If
'
'    If ComboBox1.ListIndex = -1 Then
'        MsgBox "Please select a store to transfer from."
'        Exit Sub
'    End If

    ' ... rest of your code ...
 Dim wsSales As Worksheet, wsStock As Worksheet
    Dim lastRowSales As Long, lastRowStock As Long
    Dim i As Long, j As Long
    Dim invoiceNo As Long, fromStore As String, toStore As String, itemCode As String, quantity As Long, newQuantity As Long
    invoiceNo = Val(TextBox2.Value)
    fromStore = ComboBox1.Value
    toStore = ComboBox2.Value
' ComboBox1 رصيد المخزون الاول
    fromStore1 = stocktr.Value
' ComboBox2 رصيد المخزون الثانى
    toStore2 = stocktrr.Value
    Set wsSales = Worksheets("Transferts")
    Set wsStock = Worksheets("Inventaire")
    ' Find the invoice in the Sales sheet
    lastRowSales = wsSales.Cells(wsSales.Rows.Count, "A").End(xlUp).Row
    For i = 2 To lastRowSales
        If wsSales.Cells(i, "A").Value = invoiceNo Then
            ' Get the new quantity from the user (مثال: عن طريق TextBox)
            newQuantity = Val(TextBox1.Value)
            ' Calculate the quantity difference
            quantity = wsSales.Cells(i, "H").Value
            Dim quantityDiff As Long
            quantityDiff = newQuantity + quantity
            ' Update the quantity in the Sales sheet
            wsSales.Cells(i, "H").Value = newQuantity
            wsSales.Cells(i, "k").Value = Now()  ' تاريخ التعديل
            wsSales.Cells(i, "l").Value = Environ("Username")  ' اسم المستخدم

    End If
    Next i
   ' Find the invoice in the Stock sheet
    lastRowStock = wsStock.Cells(wsStock.Rows.Count, "A").End(xlUp).Row
    For j = 2 To lastRowStock
        If wsStock.Cells(j, "A").Value = fromStore Then
            ' Get the new quantity from the user (مثال: عن طريق TextBox)
            newQuantity = Val(TextBox1.Value)
 ' Calculate the quantity difference
            quantity = wsStock.Cells(j, "D").Value
            quantityDiff = newQuantity - quantity
            ' Update the quantity in the Sales sheet
            wsStock.Cells(j, "D").Value = newQuantity + fromStore1
            ' Update quantities in the inventory
            ' ... (نفس الكود السابق لإرجاع الكميات)
    ' Find the invoice in the Stock sheet
'    lastRowStock = wsStock.Cells(wsStock.Rows.Count, "A").End(xlUp).Row
'    For j = 2 To lastRowStock
         ElseIf wsStock.Cells(j, "A").Value = toStore Then
            ' Get the new quantity from the user (مثال: عن طريق TextBox)
            newQuantity = Val(TextBox1.Value)
 ' Calculate the quantity difference
            quantity = wsStock.Cells(j, "D").Value
            quantityDiff = newQuantity + quantity
            ' Update the quantity in the Sales sheet
            wsStock.Cells(j, "D").Value = newQuantity + toStore2
           
           ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
           
           ' wsStock.Cells(j, "D").Value = newQuantity - TextBox1 + toStore2 - TextBox1
           
           ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
wsStock.Cells(j, "J").Value = Now() ' تاريخ التعديل
wsStock.Cells(j, "K").Value = Environ("Username")  ' اسم المستخدم
        End If
    Next j
    MsgBox "تم تعديل الفاتورة وإرجاع الكميات بنجاح"
End Sub

 

امين مخزن3.xlsm

تم تعديل بواسطه mahmoud nasr alhasany
رابط هذا التعليق
شارك

من فضلك سجل دخول لتتمكن من التعليق

ستتمكن من اضافه تعليقات بعد التسجيل



سجل دخولك الان
  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information