#24
by whatman » Wed Mar 06, 2013 7:41 pm
ตรง listbox ตัวซ้ายผมจะดึงข้อมูลจากคอลัมน์ D เข้ามาทั้งหมดแล้วเมื่อกดเลือก add ข้อมูลจะเข้ามา listbox ตัวขวาครับ
ทีนี้ผมต้องการให้ข้อมูลที่เลือกไว้ใน listbox ด้านขวาสมมติว่าเลือก 21M0008244 , 21M0008259 , 21M0008263
ทีนี้ผมต้องการแทนที่ข้อมูล 21M0008244 , 21M0008259 , 21M0008263 ลงไปในตำแหน่งที่ข้อมูลตัวนี้อยู่ด้วยตัว A
และเลือกข้อมูล add ชุดใหม่เข้ามา และใส่เป็น B ไปเรื่อยๆจนครบครับ
แล้วใน txtbox ด้านล่างผมใส่ A ลงไปและกดปุ่มเพื่อให้ข้อมูลโยนกลับเข้าไปแทนแต่ทำไม่ได้ครับ
Code: Select all
Private Sub CmdAddInv_Click()
If Application.Range("D1:D") = LstPoc.Value Then
Cells(WriteRow, 4) = TxtInv.Value
End If
End Sub
Private Sub CmdConvrt_Click()
Dim Handle As Integer, File_Name As String
Dim WriteRow As Long, TemArr, OneLine As String
Dim Price1, Price2, Price3 As Integer
Dim Pono() As Variant
Dim Invno() As String
Dim Chkval As Integer
Price1 = 1
Price2 = 2
Price3 = 3
Handle = FreeFile
File_Name = "D:\testrun.txt"
Open File_Name For Input As #Handle
Application.Range("A1:z999") = ""
LstPoa.Value = Null
Do While Not EOF(Handle)
Line Input #Handle, OneLine
TemArr = Split(OneLine, "|")
If UBound(TemArr) > 1 Then
WriteRow = WriteRow + 1
Cells(WriteRow, 1) = "VMI050"
Cells(WriteRow, 2) = TemArr(1)
Cells(WriteRow, 3) = TemArr(2)
Cells(WriteRow, 4) = TemArr(4)
If TemArr(4) = 9999999999# Then
Cells(WriteRow, 4) = 999999999999999#
End If
If TemArr(4) = 9999999999# Then
TemArr(4) = ""
Else
LstPoa.AddItem (TemArr(4))
End If
Cells(WriteRow, 5) = TemArr(5)
Cells(WriteRow, 6) = TemArr(5)
Cells(WriteRow, 7) = TemArr(7)
Cells(WriteRow, 8) = TemArr(8)
Cells(WriteRow, 9) = " PC"
If TemArr(4) = 9999999999# Then
Cells(WriteRow, 9) = " "
Cells(WriteRow, 11).Value = Application.Sum(Range("K1:K" & WriteRow))
End If
If TemArr(29) = "S225-1-1011-001" Then
'Cells(WriteRow, 10) = Txtprc1.Value
'Cells(WriteRow, 11) = TemArr(8) * Txtprc1
Cells(WriteRow, 10) = Price1
Cells(WriteRow, 11) = TemArr(8) * Price1
ElseIf TemArr(29) = "S225-1-1211-002" Then
Cells(WriteRow, 10) = Price2
Cells(WriteRow, 11) = TemArr(8) * Price2
ElseIf TemArr(29) = "S225-1-DUMM-001" Then
Cells(WriteRow, 10) = Price3
Cells(WriteRow, 11) = TemArr(8) * Price3
End If
Cells(WriteRow, 12) = TemArr(9)
Cells(WriteRow, 13) = TemArr(24)
Cells(WriteRow, 14) = TemArr(25)
Cells(WriteRow, 15) = TemArr(26)
End If
Loop
Close #Handle
End Sub
Private Sub CmdMove_Click()
LstPoc.AddItem (LstPoa.Value)
End Sub
Private Sub CmdSavefiles_Click()
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\testfile.txt", FileFormat:=xlTextMSDOS, _
CreateBackup:=False
End Sub
Private Sub Txtprc1_Change()
If Me.Txtprc1.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc1
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub Txtprc2_Change()
If Me.Txtprc2.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc2
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub Txtprc3_Change()
If Me.Txtprc3.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc3
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
Private Sub LstPoa_Click()
End Sub
- Attachments
-
testfile.rar
- (40.14 KiB) Downloaded 18 times
ตรง listbox ตัวซ้ายผมจะดึงข้อมูลจากคอลัมน์ D เข้ามาทั้งหมดแล้วเมื่อกดเลือก add ข้อมูลจะเข้ามา listbox ตัวขวาครับ
ทีนี้ผมต้องการให้ข้อมูลที่เลือกไว้ใน listbox ด้านขวาสมมติว่าเลือก 21M0008244 , 21M0008259 , 21M0008263
ทีนี้ผมต้องการแทนที่ข้อมูล 21M0008244 , 21M0008259 , 21M0008263 ลงไปในตำแหน่งที่ข้อมูลตัวนี้อยู่ด้วยตัว A
และเลือกข้อมูล add ชุดใหม่เข้ามา และใส่เป็น B ไปเรื่อยๆจนครบครับ
แล้วใน txtbox ด้านล่างผมใส่ A ลงไปและกดปุ่มเพื่อให้ข้อมูลโยนกลับเข้าไปแทนแต่ทำไม่ได้ครับ
[code]Private Sub CmdAddInv_Click()
If Application.Range("D1:D") = LstPoc.Value Then
Cells(WriteRow, 4) = TxtInv.Value
End If
End Sub
Private Sub CmdConvrt_Click()
Dim Handle As Integer, File_Name As String
Dim WriteRow As Long, TemArr, OneLine As String
Dim Price1, Price2, Price3 As Integer
Dim Pono() As Variant
Dim Invno() As String
Dim Chkval As Integer
Price1 = 1
Price2 = 2
Price3 = 3
Handle = FreeFile
File_Name = "D:\testrun.txt"
Open File_Name For Input As #Handle
Application.Range("A1:z999") = ""
LstPoa.Value = Null
Do While Not EOF(Handle)
Line Input #Handle, OneLine
TemArr = Split(OneLine, "|")
If UBound(TemArr) > 1 Then
WriteRow = WriteRow + 1
Cells(WriteRow, 1) = "VMI050"
Cells(WriteRow, 2) = TemArr(1)
Cells(WriteRow, 3) = TemArr(2)
Cells(WriteRow, 4) = TemArr(4)
If TemArr(4) = 9999999999# Then
Cells(WriteRow, 4) = 999999999999999#
End If
If TemArr(4) = 9999999999# Then
TemArr(4) = ""
Else
LstPoa.AddItem (TemArr(4))
End If
Cells(WriteRow, 5) = TemArr(5)
Cells(WriteRow, 6) = TemArr(5)
Cells(WriteRow, 7) = TemArr(7)
Cells(WriteRow, 8) = TemArr(8)
Cells(WriteRow, 9) = " PC"
If TemArr(4) = 9999999999# Then
Cells(WriteRow, 9) = " "
Cells(WriteRow, 11).Value = Application.Sum(Range("K1:K" & WriteRow))
End If
If TemArr(29) = "S225-1-1011-001" Then
'Cells(WriteRow, 10) = Txtprc1.Value
'Cells(WriteRow, 11) = TemArr(8) * Txtprc1
Cells(WriteRow, 10) = Price1
Cells(WriteRow, 11) = TemArr(8) * Price1
ElseIf TemArr(29) = "S225-1-1211-002" Then
Cells(WriteRow, 10) = Price2
Cells(WriteRow, 11) = TemArr(8) * Price2
ElseIf TemArr(29) = "S225-1-DUMM-001" Then
Cells(WriteRow, 10) = Price3
Cells(WriteRow, 11) = TemArr(8) * Price3
End If
Cells(WriteRow, 12) = TemArr(9)
Cells(WriteRow, 13) = TemArr(24)
Cells(WriteRow, 14) = TemArr(25)
Cells(WriteRow, 15) = TemArr(26)
End If
Loop
Close #Handle
End Sub
Private Sub CmdMove_Click()
LstPoc.AddItem (LstPoa.Value)
End Sub
Private Sub CmdSavefiles_Click()
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\testfile.txt", FileFormat:=xlTextMSDOS, _
CreateBackup:=False
End Sub
Private Sub Txtprc1_Change()
If Me.Txtprc1.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc1
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub Txtprc2_Change()
If Me.Txtprc2.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc2
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub Txtprc3_Change()
If Me.Txtprc3.Value = "" Then Exit Sub
On Error Resume Next
With Me.Txtprc3
Chkval = Evaluate(.Value)
If Left(Chkval, 5) = "Error" Then
MsgBox (" Input only number.")
.Value = Left(.Value, Len(.Value) - 1)
End If
End With
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
Private Sub LstPoa_Click()
End Sub
[/code]