: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

code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

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. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :thup: :cp: :flw: :rz: :sg: :tt: :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :ard: :arl: :aru: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#10

by yodpao.b » Thu Oct 24, 2019 3:35 pm

ขอบคุณครับ

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#9

by yodpao.b » Thu Oct 24, 2019 3:34 pm

ขอบคุณมากครับ สำหรับการสั่งให้ ใช้ stop และ f8
ทำให้หาจุดที่เป็นปัญหาได้
แต่ไม่รู้จะแก้อย่างไร เพราะไม่รู้ความหมาย
ก็เลยลบตัว code ที่เป็นปัญหา
แล้วเขียนเพิ่มใหม่โดยใช้ มาโคร ในการเขียน
ลบช่วง code ด้านล่าง

Code: Select all

''    Sheet3.Select
'    If Sheet3.Cells(6, 1).Value = 2 Or Sheet3.Cells(6, 1).Value = "" Then
'        insertrow = 5
'        If numrowcal > 0 And Sheet3.Cells(6, 1).Value <> "" Then
'            For j = 1 To numrowcal
'                Sheet3.Cells(5 + j, 1).EntireRow.Insert
'            Next j
'        End If
'    Else
'    For i = 1 To numrowin
'        If (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = Sheet8.Cells(3, 1).Value + 1) _
'        Or (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = "") Then
''            Sheet3.Rows(6 + i, 5 + i + numrowcal).Insert
''                If Sheet3.Cells(6, 1).Value = "" Then
''                    insertrow = 5
''                    For j = 1 To numrowcal
''                        Sheet3.Cells(5 + j, 1).EntireRow.Insert
''                    Next j
''                Else
'                insertrow = 5 + i
'                For j = 1 To numrowcal
'                    Sheet3.Cells(5 + i + j, 1).EntireRow.Insert
'                Next j
''                End If
'            Exit For
'        End If
'    Next i
'    End If
code ใหม่ที่ผ่านการทดสอบแล้ว

Code: Select all

Sub macro_insert(psaverow)
    Dim numrowin, numrowcal, insertrow, numman, numop, i, j As Integer
    Dim shin, shcal, shlist As Worksheet
    Set shin = ThisWorkbook.Worksheets("information")
    Set shcal = ThisWorkbook.Worksheets("cal")
    Set shlist = ThisWorkbook.Worksheets("list_other")
    numrowin = 0
    numrowcal = 0
    numman = 0
    insertrow = 5
    
'    Sheets("information").Select
    
    numop = UserForm5.TextBox35.Value
    numrowin = shin.Range("A6:A" & shin.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    numrowcal = shcal.Range("A3:A" & shcal.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    numman = shlist.Range("A2:A" & shlist.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    If Sheet8.Cells(3, 1) = "" Then
        numrowcal = 0
    End If
    '********************************************** ลบ row ครั้งนี้ (ของเดิม) ทั้งหมดออก ***********************************
    For i = numrowin To 1 Step -1
        If Sheet3.Cells(5 + i, 1) = UserForm5.TextBox35.Text Then
            Sheet3.Cells(5 + i, 1).EntireRow.Delete
        End If
    Next i
    '**********************************************************************************************************
    '**************************************** insert row ของครั้งนี้ (ของใหม่) เท่าจำนวนใหม่ **********************************
''    Sheet3.Select
'    If Sheet3.Cells(6, 1).Value = 2 Or Sheet3.Cells(6, 1).Value = "" Then
'        insertrow = 5
'        If numrowcal > 0 And Sheet3.Cells(6, 1).Value <> "" Then
'            For j = 1 To numrowcal
'                Sheet3.Cells(5 + j, 1).EntireRow.Insert
'            Next j
'        End If
'    Else
'    For i = 1 To numrowin
'        If (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = Sheet8.Cells(3, 1).Value + 1) _
'        Or (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = "") Then
''            Sheet3.Rows(6 + i, 5 + i + numrowcal).Insert
''                If Sheet3.Cells(6, 1).Value = "" Then
''                    insertrow = 5
''                    For j = 1 To numrowcal
''                        Sheet3.Cells(5 + j, 1).EntireRow.Insert
''                    Next j
''                Else
'                insertrow = 5 + i
'                For j = 1 To numrowcal
'                    Sheet3.Cells(5 + i + j, 1).EntireRow.Insert
'                Next j
''                End If
'            Exit For
'        End If
'    Next i
'    End If
    
'' ใช้แทน  insert row  ไปพรางๆก่อน ยังทำไม่ได้
     Sheets("cal").Select
     Rows("3:3").Select
     If Range("A4").Value <> "" Then
         Range(Selection, Selection.End(xlDown)).Select
     End If
     Application.CutCopyMode = False
     Selection.Copy
     Sheets("information").Select
     Rows("6:6").Select
     Selection.Insert Shift:=xlDown
    
    
    '**********************************************************************************************************
    '************************************* กรอกค่า (แทนใช้สูตร) หลังคอลัมน์ 25 เป็นต้นไป ************************************
    For i = 1 To numrowcal
        shcal.Range(shcal.Cells(2 + i, 1), shcal.Cells(2 + i, 24)).Copy shin.Range(shin.Cells(insertrow + i, 1), shin.Cells(insertrow + i, 24))
        If shin.Cells(insertrow + i, 21).Value > 0 Then
            shin.Cells(insertrow + i, 25).Value = shin.Cells(insertrow + i, 21).Value * shin.Cells(insertrow + i, 22).Value                              '25 = ค่าน้ำมันไม่มีคำสั่งเดินทาง
        Else
            shin.Cells(insertrow + i, 25).Value = ""
        End If
        For j = 1 To numman
            If shin.Cells(insertrow + i, 2).Value = shlist.Cells(1 + j, 2).Value Then
                shin.Cells(insertrow + i, 26).Value = shlist.Cells(1 + j, 6).Value                                                                                             '26 = ระดับ
            End If
        Next j
        For j = 1 To 17
            If shin.Cells(insertrow + i, 26).Value = shlist.Cells(1 + j, 8).Value And shlist.Cells(1 + j, 8).Value <> "" Then
                shin.Cells(insertrow + i, 27).Value = shlist.Cells(1 + j, 18).Value                                                                                           '27 = จัดระดับกลุ่ม
                If shin.Cells(insertrow + i, 13).Value <> "" Then
                    shin.Cells(insertrow + i, 29).Value = shin.Cells(insertrow + i, 13).Value / shlist.Cells(1 + j, 9).Value                                    '29 = จำนวนวันค่าเบี้ยเลี้ยง
                Else
                    shin.Cells(insertrow + i, 29).Value = ""
                End If
                shin.Cells(insertrow + i, 30).Value = Int(shin.Cells(insertrow + i, 14) / shlist.Cells(1 + j, 12))                                                 '30 = จำนวนวันค่าเบี้ยเลี้ยง
                shin.Cells(insertrow + i, 31).Value = Int(shin.Cells(insertrow + i, 19) / 225)                                                                          '31 = จำนวนวันค่าเสี่ยงภัย
                shin.Cells(insertrow + i, 32).Value = shlist.Cells(1 + j, 13).Value * shin.Cells(insertrow + i, 6).Value                                       '32 = ค่าแรง
                shin.Cells(insertrow + i, 33).Value = shlist.Cells(1 + j, 15).Value * shin.Cells(insertrow + i, 23).Value                                     '33 = ค่า OT 1 เท่า
                shin.Cells(insertrow + i, 34).Value = shlist.Cells(1 + j, 14).Value * shin.Cells(insertrow + i, 24).Value                                      '34 = ค่า OT 1.5 เท่า
                If shin.Cells(insertrow + i, 26).Value = shlist.Cells(2, 8).Value Then shin.Cells(insertrow + i, 35).Value = shin.Cells(insertrow + i, 6).Value * shlist.Cells(2, 16).Value _
                    : shin.Cells(insertrow + i, 36).Value = shin.Cells(insertrow + i, 6).Value * shlist.Cells(2, 17).Value: shin.Cells(insertrow + i, 37).Value = shin.Cells(insertrow + i, 6).Value '35,36,37 (เกี่ยวกับรถ)
            End If
        Next j
        If shin.Cells(insertrow + i, 9).Value = shlist.Cells(2, 24).Value Then
            shin.Cells(insertrow + i, 28).Value = shlist.Cells(2, 24).Value                                                                                                    '28 = สถานที่ทำงาน
        Else
            shin.Cells(insertrow + i, 28).Value = shlist.Cells(1, 25).Value
        End If
        shin.Cells(insertrow + i, 38).Value = Sheet1.Cells(psaverow, 7).Value                        '38 = ระดับขั้นตอนการทำงาน
        shin.Cells(insertrow + i, 39).Value = shin.Cells(insertrow + i, 32).Value * Sheet5.Cells(2, 77).Value     '0.4152                                                                                '39 = สวัสดิการ
    Next i
End Sub

    '**********************************************************************************************************
    '*************************************เรียงลำดับ ************************************
    
    ' รียงลำดับใช้แทน  insert row  ไปพรางๆก่อน ยังทำไม่ได้
    Sheets("information").Select
     Range("Table1[ครั้งที่]").Select
    ActiveWorkbook.Worksheets("information").ListObjects("Table1").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("information").ListObjects("Table1").Sort.SortFields. _
        add Key:=Range("A6"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("information").ListObjects("Table1").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

End Sub

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#8

by yodpao.b » Thu Oct 24, 2019 12:04 pm

คำถาม ที่อาจารย์สอนคือวิธี Run แบบสเตป ใช่ไหมครับ

คำอธิบาย ทำไมถึงไม่ Debug
ส่วนโปรแกรมจะ error หรือ Debug นั้นไม่เกิดขึ้นครับ
เพราะ code มันไม่ได้ผิดอะไร
แต่ผมเขียน code
จะอธิบายยังไงดี
สมมุติเขียน code ว่า copy 1 2 3 4 5 6 7 8 9 10
ถ้าเลขมีครบ 10 ตัว code ก็ run ได้ ผลก็ได้ตามต้องการ
แต่ถ้าตัวเลขมี 1 2 3 5 7 8 10 code ก็ run ได้เหมือนกัน และผลจากการคัดลอกวางควรจะเป็น 1 2 3 5 7 8 10 แต่ไม่เป็นเช่นนั้น กับเป็น 2 3 5 1
เป็นเช่นนี้ครับ ผมจึงใช้คำเรียกว่า code ผิดปกติ

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#7

by snasui » Thu Oct 24, 2019 7:29 am

:D ผมอ่านแล้วพบว่ายังไม่ทราบวิธีการ Debug Code จึงทำให้หาสาเหตุไม่ได้

การเขียน Code ที่มีประสิทธิภาพจะไม่เลือกใช้ Select เพราะทำให้หน้าจอวูบวาบ ทำงานช้า วิธีการ Debug ให้ทำตามภาพ สามารถทำได้กับทุกงานครับ

เมื่อได้ Debug และลองผิดลองถูกเองแล้วพบปัญหาเช่นไร ค่อยนำมาถามกันต่อครับ
Attachments
Debug.png
Debug.png (229.06 KiB) Viewed 54 times

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#6

by yodpao.b » Thu Oct 24, 2019 3:02 am

code ต้องสงสัยอยู่ใน โมดูล 2 ครับ

ไฟล์แนบครับ

อาจารย์จะสั่งให้ insert บรรทัดแรก แล้ววาง แล้ว เรียงลำดับใหม่
หรือ
ให้วางไว้บรรทัดสุดท้าย แล้ว เรียงลำดับใหม่
หรือ insert ระหว่างบรรทัด
ก็ได้นะครับ
แต่ผมว่า อย่างสุดท้ายน่าจะยากที่สุด และปัญหาคงเยอะด้วย

ผมทำไม่ได้จริง ๆ ครับ และ คนทำก็ย้ายไปทำงานที่อื่นแล้ว

เขาเขียน code แบบไม่ให้ขยับไปไหนเลย อยู่หน้าแรกทำงานจนเสร็จ
กด F8 ยังไม่เห็นการทำงานที่ละสเตปเลยครับ
ผมจะตัดจะต่อก็ไม่กล้ากลัวจะเสียไปกันใหญ่
จะเขียนใหม่ก็กลัวว่าไม่ดีเท่าของเขา

รบกวนอาจารย์ช่วยแก้ให้หน่อยยะครับ
และถ้าเพื่อนคนใดเข้าใจช่วยแก้ให้ด้วยนะครับ

ขอขอบคุณเป็นอย่างสูง
Attachments
EERS-0031_Tqqqq.xlsm
(379.76 KiB) Downloaded 3 times

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#5

by yodpao.b » Thu Oct 24, 2019 2:37 am

การทำงานที่ถูกต้อง
1.โปรแกรมจะสั่งให้นำข้อมูลที่เลือกไว้ จาก sheet information มาเก็บใน sheet cal (code ถูก)
2.เมื่อทำการ แก้ไข Update และ Save แล้ว โปรแกรมจะสั่งให้นำข้อมูลไปเก็บไว้ใน sheet cal (code ถูก)
3.จากนั้นโปรแกรมก็จะสั่งต่อว่าให้ไปดูใน sheet information ว่ามีลำดับครั้งที่ 3 ไหม (code ถูก)
- เมื่อเจอครั้งที่ 3 ให้ทำการลบ บรรทัดที่มีครั้งที่ 3 ออกให้หมด (code ถูก)
- จากนั้นให้ insert ระหว่างครั้งที่ 2 และ 3 จำนวน 2 บรรทัดตามข้อมูลที่ save (code ไม่ทำงานตามนี้)
(ผมไม่แน่ใจในบรรทัดบนว่า code สั่งตามนั้น code อาจจะสั่งว่า ให้ insert บรรทัดแรกลงมา 2 บรรทัด แล้วนำข้อมูลจาก
sheet cal มาวางไว้กับบรรทัดที่ insert)
จากที่ดูน่าจะเป็น insert ระหว่างครั้งที่ 2 และ 3 ครับ
จบขั้นตอนการทำงานครับ
code ต้องสงสัย

Code: Select all

Sub macro_insert(psaverow)
    Dim numrowin, numrowcal, insertrow, numman, numop, i, j As Integer
    Dim shin, shcal, shlist As Worksheet
    Set shin = ThisWorkbook.Worksheets("information")
    Set shcal = ThisWorkbook.Worksheets("cal")
    Set shlist = ThisWorkbook.Worksheets("list_other")
    numrowin = 0
    numrowcal = 0
    numman = 0
    insertrow = 5
    
'    Sheets("information").Select
    
    numop = UserForm5.TextBox35.Value
    numrowin = shin.Range("A6:A" & shin.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    numrowcal = shcal.Range("A3:A" & shcal.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    numman = shlist.Range("A2:A" & shlist.Cells(Rows.count, "A").End(xlUp).Row).Rows.count
    If Sheet8.Cells(3, 1) = "" Then
        numrowcal = 0
    End If
    '********************************************** ลบ row ครั้งนี้ (ของเดิม) ทั้งหมดออก ***********************************
    For i = numrowin To 1 Step -1
        If Sheet3.Cells(5 + i, 1) = UserForm5.TextBox35.Text Then
            Sheet3.Cells(5 + i, 1).EntireRow.Delete
        End If
    Next i
    '**********************************************************************************************************
    '**************************************** insert row ของครั้งนี้ (ของใหม่) เท่าจำนวนใหม่ **********************************
'    Sheet3.Select
    If Sheet3.Cells(6, 1).Value = 2 Or Sheet3.Cells(6, 1).Value = "" Then
        insertrow = 5
        If numrowcal > 0 And Sheet3.Cells(6, 1).Value <> "" Then
            For j = 1 To numrowcal
                Sheet3.Cells(5 + j, 1).EntireRow.Insert
            Next j
        End If
    Else
    For i = 1 To numrowin
        If (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = Sheet8.Cells(3, 1).Value + 1) _
        Or (Sheet3.Cells(5 + i, 1).Value = Sheet8.Cells(3, 1).Value - 1 And Sheet3.Cells(6 + i, 1).Value = "") Then
'            Sheet3.Rows(6 + i, 5 + i + numrowcal).Insert
'                If Sheet3.Cells(6, 1).Value = "" Then
'                    insertrow = 5
'                    For j = 1 To numrowcal
'                        Sheet3.Cells(5 + j, 1).EntireRow.Insert
'                    Next j
'                Else
                insertrow = 5 + i
                For j = 1 To numrowcal
                    Sheet3.Cells(5 + i + j, 1).EntireRow.Insert
                Next j
'                End If
            Exit For
        End If
    Next i
    End If
    
    '**********************************************************************************************************
    '************************************* กรอกค่า (แทนใช้สูตร) หลังคอลัมน์ 25 เป็นต้นไป ************************************
    For i = 1 To numrowcal
        shcal.Range(shcal.Cells(2 + i, 1), shcal.Cells(2 + i, 24)).Copy shin.Range(shin.Cells(insertrow + i, 1), shin.Cells(insertrow + i, 24))
        If shin.Cells(insertrow + i, 21).Value > 0 Then
            shin.Cells(insertrow + i, 25).Value = shin.Cells(insertrow + i, 21).Value * shin.Cells(insertrow + i, 22).Value                              '25 = ค่าน้ำมันไม่มีคำสั่งเดินทาง
        Else
            shin.Cells(insertrow + i, 25).Value = ""
        End If
        For j = 1 To numman
            If shin.Cells(insertrow + i, 2).Value = shlist.Cells(1 + j, 2).Value Then
                shin.Cells(insertrow + i, 26).Value = shlist.Cells(1 + j, 6).Value                                                                                             '26 = ระดับ
            End If
        Next j
        For j = 1 To 17
            If shin.Cells(insertrow + i, 26).Value = shlist.Cells(1 + j, 8).Value And shlist.Cells(1 + j, 8).Value <> "" Then
                shin.Cells(insertrow + i, 27).Value = shlist.Cells(1 + j, 18).Value                                                                                           '27 = จัดระดับกลุ่ม
                If shin.Cells(insertrow + i, 13).Value <> "" Then
                    shin.Cells(insertrow + i, 29).Value = shin.Cells(insertrow + i, 13).Value / shlist.Cells(1 + j, 9).Value                                    '29 = จำนวนวันค่าเบี้ยเลี้ยง
                Else
                    shin.Cells(insertrow + i, 29).Value = ""
                End If
                shin.Cells(insertrow + i, 30).Value = Int(shin.Cells(insertrow + i, 14) / shlist.Cells(1 + j, 12))                                                 '30 = จำนวนวันค่าเบี้ยเลี้ยง
                shin.Cells(insertrow + i, 31).Value = Int(shin.Cells(insertrow + i, 19) / 225)                                                                          '31 = จำนวนวันค่าเสี่ยงภัย
                shin.Cells(insertrow + i, 32).Value = shlist.Cells(1 + j, 13).Value * shin.Cells(insertrow + i, 6).Value                                       '32 = ค่าแรง
                shin.Cells(insertrow + i, 33).Value = shlist.Cells(1 + j, 15).Value * shin.Cells(insertrow + i, 23).Value                                     '33 = ค่า OT 1 เท่า
                shin.Cells(insertrow + i, 34).Value = shlist.Cells(1 + j, 14).Value * shin.Cells(insertrow + i, 24).Value                                      '34 = ค่า OT 1.5 เท่า
                If shin.Cells(insertrow + i, 26).Value = shlist.Cells(2, 8).Value Then shin.Cells(insertrow + i, 35).Value = shin.Cells(insertrow + i, 6).Value * shlist.Cells(2, 16).Value _
                    : shin.Cells(insertrow + i, 36).Value = shin.Cells(insertrow + i, 6).Value * shlist.Cells(2, 17).Value: shin.Cells(insertrow + i, 37).Value = shin.Cells(insertrow + i, 6).Value '35,36,37 (เกี่ยวกับรถ)
            End If
        Next j
        If shin.Cells(insertrow + i, 9).Value = shlist.Cells(2, 24).Value Then
            shin.Cells(insertrow + i, 28).Value = shlist.Cells(2, 24).Value                                                                                                    '28 = สถานที่ทำงาน
        Else
            shin.Cells(insertrow + i, 28).Value = shlist.Cells(1, 25).Value
        End If
        shin.Cells(insertrow + i, 38).Value = Sheet1.Cells(psaverow, 7).Value                        '38 = ระดับขั้นตอนการทำงาน
        shin.Cells(insertrow + i, 39).Value = shin.Cells(insertrow + i, 32).Value * Sheet5.Cells(2, 77).Value     '0.4152                                                                                '39 = สวัสดิการ
    Next i
End Sub
มีต่อ

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#4

by yodpao.b » Thu Oct 24, 2019 2:16 am

ขั้นตอนการทำงานที่ผิดปกติ
1.คลิกเซล D5 ใน sheet Log
2.ฟอร์จะแสดงขึ้นมา เลือก พขร
3.พืมพ์ 100 ในช่องค่า taxi
4.คลิก update
5.คลืก SAVE
7.JPG
7.JPG (15.49 KiB) Viewed 61 times
ผลที่ได้
6.JPG
6.JPG (45.16 KiB) Viewed 61 times
จากรูปจะเห็นว่าข้อมูลที่แสดงไม่เรียงลำดับ และข้อมูลครั้งที่ 3 ถูก copy วางทับในบรรทัดที่ 1และ2
____________________________________________________

มีต่อ

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#3

by yodpao.b » Thu Oct 24, 2019 1:47 am

วิธีทำให้ค่าในช่องที่วงกลมหายไป
ใน sheet Log
1. ลบครั้งที่ 2 ออกก่อน
2.แล้วจึงมาลบจำนวนคนในช่องผู้ปฎิบัติงาน
3.พิมพ์เลข 2 เข้าไปใหม่ดังรูป
5.JPG
5.JPG (48.15 KiB) Viewed 62 times
ใน sheet information
1.ลบทั้งแถว
4.JPG
4.JPG (39.64 KiB) Viewed 62 times
มีต่อ ขั้นตอนการทำงาน

Re: code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#2

by yodpao.b » Thu Oct 24, 2019 1:32 am

ผมขอแสดงผลในรูปแบบผิดปกติที่ code ทำงานไม่ถูกต้อง
2.JPG
2.JPG (26.53 KiB) Viewed 63 times
จากรูปจะเห็นว่าใน sheet Log ในช่องผู้ปฏิบัติงาน มีตัวเลขจำนวนคนไม่มี

3.JPG
3.JPG (24.01 KiB) Viewed 63 times
จากรูปจะเห็นว่าใน sheet information ในช่องครั้ง มีตรั้งที่ 1,3,4 ไม่ครบ ตาม sheet Log
ครั้งที่ 2 หายไป

ถ้าเป็นไปตามนี้การทำงานของ code จะไม่ถูกต้องครับ

ผมมองว่าปัญหานี้ไม่น่าเกิดขึันได้เพราะไม่น่าเป็นไปได้ที่ไปทำงานแล้วจะไม่มีคนทำงานก็เลยปล่อยผ่าน
แต่ผู้ปฏิบัติงาน บอกว่ามีกรณีแบบนี้อาจเกิดขึ้นได้แต่ผมจำไม่ได้ว่าคืออะไรที่ทำให้เกิดกรณีแบบนี้แต่น่าจะเป็นเกีย่วกับการนำเครื่องมือไปติดไว้

__________________________________________________________________________
มีต่อ ขั้นตอนการทำงาน

code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

#1

by yodpao.b » Thu Oct 24, 2019 1:22 am

code ไม่ insert ให้เพราะข้อมูลมีไม่ครบ

ขอเกริ่นก่อนครับ
น้องที่ทำงานเขาแก้ code เดิมใหม่ เขาไม่ใช้ .Select ผมเลยมองไม่เห็นเวลา run code เลย
ไฟล์นี้ได้นำไปใช้งานแล้วและคิดว่าจะเกิดปัญหาแน่ในสักวันหนึ่ง แต่เพราะแก้ไม่ได้จึงให้ใช้งานไปก่อน
นึกไม่ถีงจะทำให้ฐานข้อมูลเสียหายไปด้วย

เริ่มถามนะครับ
ไฟล์นี้ถ้าพิมพ์ข้อมูลตามลำดับขั้นตอนจะทำงานได้เป็นปกติ
ผมขอแสดงผลในรูปแบบปกติที่ code ทำงานได้ถูกต้องนะครับ
0.JPG
0.JPG (27.8 KiB) Viewed 64 times
จากรูปจะเห็นว่าใน sheet Log ในช่องผู้ปฏิบัติงาน มีครบทุกช่องตามจำนวนตรั้ง
1.JPG
1.JPG (28.76 KiB) Viewed 64 times
จากรูปจะเห็นว่าใน sheet information ในช่องครั้ง มีตรั้งที่ 1,2,3,4 ครบ ตาม sheet Log

ถ้าเป็นไปตามนี้การทำงานของ code จะถูกต้องครับ
____________________________________________________

มีต่อ add รูปไม่ได้
Attachments
2.JPG
2.JPG (26.53 KiB) Viewed 64 times

Top