Page 1 of 1
ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Sun Nov 19, 2023 1:20 pm
by nongmayza
นำข้อมูลบันทึกในกล่อง listbox แล้ว ลองบันทึกที่ชีตแล้ว บันทึกได้ แต่ติดตรงที่เวลาบันทึกจะบันทึกต่อไปเรื่อยๆ แต่ความต้องการคือ
แถวข้อมูลที่2 ให้บันทึกอีก1แถว ในชีตค่ะ รบกวนช่วยดูให้หน่อยค่ะ
พร้อมแนบไฟล์ตัวอย่างมาค่ะ
Code: Select all
Private Sub CommandButton2_Click()
Dim r As Long, i As Integer, j As Integer, k As Integer
With Sheets("Database")
r = .Range("x" & Rows.Count).End(xlUp).Row + 1
.Cells(r, 24) = namejob.Value
k = 25
For i = 0 To ListBox1.ListCount - 1
For j = 0 To 9
.Cells(r, k) = ListBox1.List(i, j)
k = k + 1
Next j
Next i
End With
End Sub
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Mon Nov 20, 2023 7:01 am
by snasui

กรุณาลำดับวิธีการทดสอบมาด้วยว่าต้องคลิกปุ่มไหน กรอกค่าไหน ตามลำดับอย่างไรเพื่อให้เกิดผลลัพธ์ตามที่แจ้งมา พร้อมอธิบายว่า หากถูกต้อ่งโปรแกรมจะต้องแสดงผลอย่างไร จะได้สะดวกในการทำความเข้าใจของเพื่อนสมาชิกครับ
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Wed Nov 22, 2023 12:59 pm
by nongmayza
ขอบคุณน่ะค่ะ ในส่วนนี้ แก้ไขเรียบร้อยแล้วค่ะ
แต่ติดปัญหาอีกอย่างนึงค่ะ
ความต้องการคือ ให้คลิ๊กที่ listbox1 แล้ว ข้อมูลที่คลิ๊กไปโชว์ที่ combobox7 (ในส่วนนี้ทำได้เรียบร้อยแล้ว)
แต่ที่ยังไม่ได้คือ
*** รายการที่คลิ๊กใน listbox1 ให้ลบ ออกไปจาก listbox1 เมื่อข้อมูลไปโชว์ที่ combobox7 ค่ะ ***
รบกวนช่วยดูให้หน่อยค่ะว่าติดที่ ตรงไหนค่ะ พร้อมแนบไฟล์มาให้แล้วค่ะ
Code: Select all
Private Sub ListBox1_Click()
Dim x As Integer
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
ComboBox7.Text = ListBox1.list(x)
End If
Next x
For x = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(x) = True Then
ListBox1.RemoveItem (x)
End If
Next x
End Sub
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Wed Nov 22, 2023 1:36 pm
by snasui

กรุณาแนบไฟล์ที่ได้ปรับปรุงล่าสุดประกอบคำถามมาด้วยและอย่าลืมแจ้งวิธีการทดสอบตามโพสต์ #2

ครับ
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Wed Nov 22, 2023 5:11 pm
by nongmayza
ความต้องการคือ ให้คลิ๊กที่ listbox1 แล้ว ข้อมูลที่คลิ๊กไปโชว์ที่ combobox7 (ในส่วนนี้ทำได้เรียบร้อยแล้ว)
แต่ที่ยังไม่ได้คือ
*** รายการที่คลิ๊กใน listbox1 ให้ลบ ออกไปจาก listbox1 เมื่อข้อมูลไปโชว์ที่ combobox7 ค่ะ ***
วิธีทดสอบ
กด ปุ้ม โชว์รายการ
ข้อมูลจะขึ้นที่ listbox1 เมื่อเลือกข้อมูลใน listbox1 ข้อมูลจะไปแสดงที่ combobox7 ค่ะ แล้วก็จะลบข้อมูลใน listbox1 ที่ไปแสดงที่ combobox7 ค่ะ แต่ติดปัญหาตอนลบ ไม่สามารถลบได้ค่ะ
รบกวนช่วยดูให้หน่อยค่ะว่าติดที่ ตรงไหนค่ะ พร้อมแนบไฟล์มาให้แล้วค่ะ
Code: Select all
Private Sub ListBox1_Click()
Dim x As Integer
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
ComboBox7.Text = ListBox1.list(x)
End If
Next x
For x = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(x) = True Then
ListBox1.RemoveItem (x)
End If
Next x
End Sub
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Wed Nov 22, 2023 8:30 pm
by snasui

ตัวอย่าง Code ตามด้านล่าง
ลองปรับใช้ดูครับ
Code: Select all
Dim isUpdated As Boolean
Private Sub ComboBox7_Change()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Database")
ws.Cells(127, 135).Value = Me.ComboBox7.Value
isUpdated = True
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer, j As Integer
'ListBox1.RowSource = "Database!ED52:ED71"
With Sheets("Database")
For i = 52 To 71
If .Cells(i, "ed").Value <> "" Then
Me.ListBox1.AddItem .Cells(i, "ed").Value
End If
j = j + 1
Next i
End With
isUpdated = False
End Sub
Private Sub ListBox1_Click()
Dim x As Integer
If isUpdated Then
isUpdated = False
Exit Sub
End If
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
ComboBox7.Text = ListBox1.List(x)
Exit For
End If
Next x
For x = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(x) Then
ListBox1.RemoveItem (x)
End If
Next x
End Sub
Re: ช่วยด้วยค่ะ บันทึกlistbox ลงsheetไม่ได้ค่ะ
Posted: Wed Nov 22, 2023 8:45 pm
by nongmayza
ได้แล้วค่ะ ขอบคุณค่ะ ทำงานได้สะดวกขึ้นมากเลยค่ะ