:D snasui.com ยินดีต้อนรับ :D
ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย :thup: สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ :arrow: ระบุ Version ของ Excel
:!: โปรดทราบ :!:
  1. กรุณาอ่านกฎการใช้บอร์ด (Forum rules) ในตำแหน่งด้านบนของแต่ละบอร์ด
  2. การสมัครสมาชิก การ Login การกู้คืนรหัสผ่าน
    1. สมัครสมาชิกดูขั้นตอนได้ที่ :arrow: สมัครสมาชิก
    2. Login เข้าระบบโดยคลิกปุ่ม Login ตรงมุมขวาบนของหน้านี้ :roll:
    3. การ Login ผ่าน Facebook ดูวิธีที่ :arrow: Login ผ่าน Facebook
    4. ลืมรหัสผ่านสามารถรับรหัสใหม่ได้ที่ :arrow: Reset รหัสผ่าน
  3. มีปัญหาการใช้งาน แจ้งผู้ดูแลระบบได้ที่ :arrow: ติดต่อผู้ดูแลระบบ
  4. กำหนดการตั้งค่าส่วนตัว เช่นตั้งค่าภาษาเป็นไทยหรืออังกฤษดูได้ที่ :arrow: ตั้งค่าส่วนตัว
  5. การตั้งและตอบกระทู้ดูได้ที่ :arrow: วิธีการตั้งและตอบกระทู้
  6. การจัดรูปแบบตัวอักษรด้วย bbcode ในช่องแสดงความคิดเห็นดูได้ที่ :arrow: จัดรูปแบบตัวอักษร
  7. กำหนดขนาดตัวอักษรใน Browser ดูได้ที่ :arrow: กำหนดขนาดตัวอักษรใน Browser

การ Update ข้อมูลที่มีการแก้ไขครับ

ฟอรัมถาม-ตอบปัญหาการใช้งาน MS Excel and VBA
Forum rules
  1. ไม่อนุญาตให้ใช้ภาษาแชทในการถามและตอบปัญหา ไม่ใช้คำว่า "คับ" หรือ "อ่ะครับ" แทนคำว่า "ครับ" ไม่ใช้คำว่า "เด๋ว" แทนคำว่า "เดี๋ยว" เป็นต้น เนื่องจากเมื่อแปลเป็นภาษาต่างประเทศแล้วจะให้ความหมายผิดไปจากที่ควรจะเป็น
  2. ห้ามถามโดยระบุชื่อผู้ตอบและต้องตั้งชื่อกระทู้ให้สื่อถึงปัญหาที่จะถาม ไม่ตั้งชื่อว่า ช่วยด้วยครับ, มีปัญหามาปรึกษาครับ เป็นต้น
  3. กรุณาอธิบายปัญหาและระบุคำตอบที่ต้องการมาในกระทู้ด้วยเสมอถึงแม้จะอธิบายไว้ในไฟล์แนบแล้วก็ตาม ทั้งนี้เพื่ออำนวยความสะดวกแก่เพื่อนสมาชิกในการค้นหาข้อมูล
  4. กรุณาแนบไฟล์ตัวอย่างพร้อมแสดงคำตอบที่ถูกต้องมาในไฟล์ด้วยเพื่อให้ง่ายต่อการทำความเข้าใจและสะดวกต่อการตอบคำถาม (ขนาดไฟล์ไม่เกิน 500Kb ขนาดภาพไม่เกิน 800*600 Pixel) ไม่แนบเป็น Link มาจากแหล่งอื่นที่อาจจะถูกลบทิ้งไปโดยต้นทางในภายหลัง นอกจากนี้ไม่ควรแนบไฟล์ที่มีข้อมูลสำคัญอันก่อให้เกิดความเสียหายกับตนเองและผู้อื่น
  5. กรณีเป็นคำถามเกี่ยวกับ Programming เช่น VBA, VB.Net, C#, SQL ฯลฯ ต้องลองเขียนมาเองก่อนเสมอ ถามเฉพาะที่ติดปัญหา ระบุ Module, Procedure ที่ติดปัญหาให้ชัดเจน กรุณาโพสต์ Code ให้แสดงเป็น Code คือเปิดด้วย [code] และปิดด้วย [/code] ตัวอย่างเช่น [code]dim r as range[/code] เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)
  6. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
Godtheking
Member
Member
Posts: 33
Joined: Thu Feb 23, 2023 7:02 am
Excel Ver: 2010,365

การ Update ข้อมูลที่มีการแก้ไขครับ

#1

Post by Godtheking »

ตอนนี้ผมติดปัญหาเรื่องของการ UPDATE
ผม Edit ข้อมูลขึ้นมาแก้ไข แร้วกด Update ข้อมูลของผมที่ Update ไม่ได้ทับตัวที่ Edit
ขั้นมาแต่ข้อมูลลงไปอยู่ล่าสุด ผมต้องปรับแก้ Code ตรงไหนบ้างครับ

Code: Select all

Sub Update_Weight() '''    *** Update   *** '''
    Dim sh As Worksheet
    Dim iRow As Long
    Dim x As Object
    Dim str As String

    For Each x In frmForm.Frame5.Controls
        If x.Value = True Then
            str = x.Name
            Exit For
        End If
    Next

        Set sh = ThisWorkbook.Sheets(str)

        If frmForm.txtRowNumber.Value = "" Then
            iRow = sh.Range("A" & Rows.Count).End(xlUp).Row + 1
        Else
            iRow = frmForm.txtRowNumber.Value
        End If
            If frmForm.txtPart.Value = "" Then
                MsgBox "Please specify Part No."
            ElseIf frmForm.txtName.Value = "" Then
                MsgBox "Please specify PART Name."
            ElseIf Len(frmForm.txtModel.Value) <> 3 Then
                MsgBox "Please specify Model"
            ElseIf Len(frmForm.txtControl.Value) <> 4 Then
                MsgBox "Please specify CONTROL"
            ElseIf frmForm.txtQty.Value = "" Then
                MsgBox "Please specify Q'TY"
            ElseIf frmForm.txtPiece.Value = "" Then
                MsgBox "Please specify By Piece"
            ElseIf Len(frmForm.txtDate.Value) <> 8 Then
                MsgBox "Please specify Date."
            ElseIf Len(frmForm.txtID.Value) <> 4 Then
                frmForm.txtPart.SetFocus
            Else
            
             With sh
                .Cells(iRow, 1) = iRow - 2
                .Cells(iRow, 2) = frmForm.txtPart.Value
                .Cells(iRow, 3) = frmForm.txtName.Value
                .Cells(iRow, 4) = frmForm.txtModel.Value
                .Cells(iRow, 5) = frmForm.txtControl.Value
                .Cells(iRow, 6) = frmForm.txtQty.Value
                .Cells(iRow, 7) = frmForm.txtBox1.Value
                .Cells(iRow, 8) = frmForm.txtBox2.Value
                .Cells(iRow, 9) = frmForm.txtBox3.Value
                .Cells(iRow, 10) = frmForm.txtBox4.Value
                .Cells(iRow, 11) = frmForm.txtBox5.Value
                .Cells(iRow, 12) = frmForm.txtBox6.Value
                .Cells(iRow, 13) = frmForm.txtBox7.Value
                .Cells(iRow, 14) = frmForm.txtBox8.Value
                .Cells(iRow, 15) = frmForm.txtBox9.Value
                .Cells(iRow, 16) = frmForm.txtBox10.Value
                .Cells(iRow, 17) = frmForm.txtPiece.Value
                .Cells(iRow, 18) = frmForm.txtStandard.Value
                .Cells(iRow, 19) = frmForm.txtLower.Value
                .Cells(iRow, 20) = frmForm.txtUpper.Value
                .Cells(iRow, 21) = frmForm.txtPercent.Value
                .Cells(iRow, 22) = frmForm.txtPercent1.Value
                .Cells(iRow, 23) = frmForm.txtID.Value
                .Cells(iRow, 24) = frmForm.txtDate.Value
                .Cells(iRow, 25) = frmForm.txtIDName.Value
                .Cells(iRow, 26) = Left(frmForm.txtPart.Value, 8)
                .Cells(iRow, 27) = frmForm.txtCheck.Value
            End With
        End If
    'Call SaveData
 End Sub
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 30746
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: การ Update ข้อมูลที่มีการแก้ไขครับ

#2

Post by snasui »

:D ถ้ายังตั้งใจแขียน "แล้ว" เป็น "แร้ว" มาอีกสักรอบผม Block นะครับ
Godtheking
Member
Member
Posts: 33
Joined: Thu Feb 23, 2023 7:02 am
Excel Ver: 2010,365

Re: การ Update ข้อมูลที่มีการแก้ไขครับ

#3

Post by Godtheking »

ขอโทษครับผมจะระวังในการใช้ภาษาครับ
Godtheking wrote: Wed Mar 06, 2024 11:50 am ตอนนี้ผมติดปัญหาเรื่องของการ UPDATE
ผม Edit ข้อมูลขึ้นมาแก้ไข แล้วกด Update ข้อมูลของผมที่ Update ไม่ได้ทับตัวที่ Edit
ขั้นมาแต่ข้อมูลลงไปอยู่ล่าสุด ผมต้องปรับแก้ Code ตรงไหนบ้างครับ

Code: Select all

Sub Update_Weight() '''    *** Update   *** '''
    Dim sh As Worksheet
    Dim iRow As Long
    Dim x As Object
    Dim str As String

    For Each x In frmForm.Frame5.Controls
        If x.Value = True Then
            str = x.Name
            Exit For
        End If
    Next

        Set sh = ThisWorkbook.Sheets(str)

        If frmForm.txtRowNumber.Value = "" Then
            iRow = sh.Range("A" & Rows.Count).End(xlUp).Row + 1
        Else
            iRow = frmForm.txtRowNumber.Value
        End If
            If frmForm.txtPart.Value = "" Then
                MsgBox "Please specify Part No."
            ElseIf frmForm.txtName.Value = "" Then
                MsgBox "Please specify PART Name."
            ElseIf Len(frmForm.txtModel.Value) <> 3 Then
                MsgBox "Please specify Model"
            ElseIf Len(frmForm.txtControl.Value) <> 4 Then
                MsgBox "Please specify CONTROL"
            ElseIf frmForm.txtQty.Value = "" Then
                MsgBox "Please specify Q'TY"
            ElseIf frmForm.txtPiece.Value = "" Then
                MsgBox "Please specify By Piece"
            ElseIf Len(frmForm.txtDate.Value) <> 8 Then
                MsgBox "Please specify Date."
            ElseIf Len(frmForm.txtID.Value) <> 4 Then
                frmForm.txtPart.SetFocus
            Else
            
             With sh
                .Cells(iRow, 1) = iRow - 2
                .Cells(iRow, 2) = frmForm.txtPart.Value
                .Cells(iRow, 3) = frmForm.txtName.Value
                .Cells(iRow, 4) = frmForm.txtModel.Value
                .Cells(iRow, 5) = frmForm.txtControl.Value
                .Cells(iRow, 6) = frmForm.txtQty.Value
                .Cells(iRow, 7) = frmForm.txtBox1.Value
                .Cells(iRow, 8) = frmForm.txtBox2.Value
                .Cells(iRow, 9) = frmForm.txtBox3.Value
                .Cells(iRow, 10) = frmForm.txtBox4.Value
                .Cells(iRow, 11) = frmForm.txtBox5.Value
                .Cells(iRow, 12) = frmForm.txtBox6.Value
                .Cells(iRow, 13) = frmForm.txtBox7.Value
                .Cells(iRow, 14) = frmForm.txtBox8.Value
                .Cells(iRow, 15) = frmForm.txtBox9.Value
                .Cells(iRow, 16) = frmForm.txtBox10.Value
                .Cells(iRow, 17) = frmForm.txtPiece.Value
                .Cells(iRow, 18) = frmForm.txtStandard.Value
                .Cells(iRow, 19) = frmForm.txtLower.Value
                .Cells(iRow, 20) = frmForm.txtUpper.Value
                .Cells(iRow, 21) = frmForm.txtPercent.Value
                .Cells(iRow, 22) = frmForm.txtPercent1.Value
                .Cells(iRow, 23) = frmForm.txtID.Value
                .Cells(iRow, 24) = frmForm.txtDate.Value
                .Cells(iRow, 25) = frmForm.txtIDName.Value
                .Cells(iRow, 26) = Left(frmForm.txtPart.Value, 8)
                .Cells(iRow, 27) = frmForm.txtCheck.Value
            End With
        End If
    'Call SaveData
 End Sub
User avatar
snasui
Site Admin
Site Admin
Posts: 30746
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: การ Update ข้อมูลที่มีการแก้ไขครับ

#4

Post by snasui »

:D ผมต้องทดสอบอย่างไรให้พบปัญหานั้น ช่วยลำดับมาให้ด้วยจะได้เข้าถึงปัญหาโดยไวครับ
Godtheking
Member
Member
Posts: 33
Joined: Thu Feb 23, 2023 7:02 am
Excel Ver: 2010,365

Re: การ Update ข้อมูลที่มีการแก้ไขครับ

#5

Post by Godtheking »


เปิด Userform ที่ sheet Trim ขึ้นมาครับและเลือกที่ Line Packing ให้เลือก Trim ครับ
และจะมีข้อมูลขึ้นมาให้ เลือกข้อมูลด้านล่าง 1 ข้อและกด Edit และลองแก้ไขข้อมูล
เสร็จแล้วกด Update ครับ
พอกด Update แล้วข้อมูลที่จะ Update ไม่ได้วางทับตัวที่ Edit ขึ้นมาครับแต่ข้อมูลไปเพิ่มบรรทัดใหม่ครับ
You do not have the required permissions to view the files attached to this post.
User avatar
puriwutpokin
Guru
Guru
Posts: 3704
Joined: Fri Jan 04, 2013 9:49 pm
Location: Bangkok
Excel Ver: MS.365

Re: การ Update ข้อมูลที่มีการแก้ไขครับ

#6

Post by puriwutpokin »

ลองปรับตามนี้ดูครับ

Code: Select all

Sub Update_Weight() '''    *** Update   *** '''
    Dim sh As Worksheet
    Dim iRow As Long
    Dim lrow As Long
    Dim x As Object
    Dim str As String

    For Each x In frmForm.Frame5.Controls
        If x.Value = True Then
            str = x.Name
            Exit For
        End If
    Next

        Set sh = ThisWorkbook.Sheets(str)
      lrow = sh.Range("b" & sh.Rows.Count).End(xlUp).Row
        If frmForm.txtRowNumber.Value = "" Then
           ' iRow = sh.Range("A" & Rows.Count).End(xlUp).Row + 1
            iRow = Application.Match(frmForm.txtPart.Value, sh.Range("b1:b" & lrow), 0)
        Else
            iRow = frmForm.txtRowNumber.Value
        End If
'Other Code
:shock: :roll: :D
Post Reply