
เรียนอาจารย์และเพื่อนสมาชิกทุกคน
ปํญหาการ select copy ขออธิบายดังนี้
1.เมื่อเปิด userform ขึ้นมาแล้ว รายการชื่อและแผนก ใน Listbox1 ทางด้านซ้ายจะแสดงรายการออกมาทั้งหมดแล้ว
2.ต่อมาเลือกกดปุ่ม ชื่อ แผนก 1 หรือ ชื่อ แผนก 2 ก็จะแสดงรายการ ใน Listbox2 ทางด้านขวาจะแสดงรายการออกมาทั้งหมดได้เรียบร้อยแล้ว
3.จากนั้นเลือก รายการ ชื่อ แผนก ใน Listbox1 ตามความต้องการ เมื่อเลือกรายการได้แล้ว
4.ทำการกดปุ่ม SAVE เพื่อ SAVE รายการใน Listbox1 ไปไว้ ใน Listbox 2 ว่าจะ SAVE ไปไว้ใน ชื่อ แผนก 1
หรือ ชื่อ แผนก 2
code ที่ได้เขียนขึ้นมา ทำการ SAVE CommandButton4_Click() ได้ครับ แต่ยังไม่ครอบคุลุมในสิ่งต้องการ
ปัญหา คือ SAVE แล้ว ต้องการให้ SAVE นำ ชื่อ และ แผนก มาวางไว้ที่แถวสุดท้าย โดยมาทั้ง ชื่อ และแผนก
เช่น Select ชื่อ ddddd แผนก asds5 ใน column I , J แล้ว ไปวางที่ ชื่อ 1 แผนก1 ใน column B , C
แต่ code ที่เขียน copy ชื่อ ddddd แผนก ccvcvc ซื่งไม่ได้ตามต้องการ ที่ต้องการคือ ชื่อ ddddd แผนก asds5
และการเลือก ชื่อ แผนก 1 หรือ ชื่อ แผนก 2 ผมเขียนให้อยู่ใน CommandButton4_Click()
พอเลือก ชื่อ แผนก 2 มาแสดงใน Listbox 2 ด้านขวา กด SAVE ไม่ copy ไปไว้ใน column D , C ครับ
Code: Select all
Private Sub CommandButton4_Click() ' SAVE
Dim i, c As Integer
Dim b, d As Integer
For i = 0 To Me.ListBox2.ListCount - 1
For c = 1 To Me.ListBox2.ListCount - 1
If Me.ListBox1.Selected(i) = True Then
Cells(Me.ListBox2.ListCount + 2, 2) = Me.ListBox1.List(i)
Cells(Me.ListBox2.ListCount + 2, 3) = Me.ListBox1.List(c)
End If
Me.ListBox1.Selected(i) = False
Next c
Next i
For b = 0 To Me.ListBox2.ListCount - 1
For d = 1 To Me.ListBox2.ListCount - 1
If Me.ListBox1.Selected(b) = True Then
Cells(Me.ListBox2.ListCount + 2, 4) = Me.ListBox1.List(b)
Cells(Me.ListBox2.ListCount + 2, 5) = Me.ListBox1.List(d)
End If
Me.ListBox1.Selected(b) = False
Next d
Next b
End Sub
ปัญหาที่ code นี้ ชื่อ1 แผนก1
Code: Select all
For c = 1 To Me.ListBox2.ListCount - 1
Code: Select all
Cells(Me.ListBox2.ListCount + 2, 2) = Me.ListBox1.List(i)
Cells(Me.ListBox2.ListCount + 2, 3) = Me.ListBox1.List(c)
และ ที่ ชื่อ 2 แผนก 2
Code: Select all
For d = 1 To Me.ListBox2.ListCount - 1
Code: Select all
Cells(Me.ListBox2.ListCount + 2, 4) = Me.ListBox1.List(b)
Cells(Me.ListBox2.ListCount + 2, 5) = Me.ListBox1.List(d)
ขอบคุุณครับ
add and select copy.xlsm
You do not have the required permissions to view the files attached to this post.