: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

บันทึกข้อมูล

ฟอรัมถาม-ตอบปัญหาการใช้งาน 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. กรุณาแจ้งผลการใช้งานเมื่อได้รับคำตอบว่าตรงกับความต้องการหรือไม่
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#21

Post by Benmore »

snasui wrote::D ไฟล์ที่แนบมายังไม่มีการปรับ Code ที่ผมตอบไปด้านบน ปรับมาก่อนแล้วแนบมาใหม่ครับ

Code: Select all

For Each ct In Me.Frame2.Controls
 If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 7).Value = ct.Caption
 Exit For
 End If
Next ct
For Each ct In Me.Frame5.Controls
 If VBA.Left(ct.Name, 4) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 8).Value = ct.Caption
 Exit For
 End If
Next ct
แก้ไขประมาณนี้ค่ะ
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#22

Post by snasui »

:D แจ้งตัวอย่างข้อมูลทดสอบมาด้วยครับ control ใดกรอกค่าใดบ้างครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#23

Post by Benmore »

ภาพ 1 :ard:
รูป.png
เมื่อเลือกข้อมูลครบแล้วตามภาพ
ภาพที่ 2 :ard:
342.png
ข้อมูลในวงกลมในภาพที่ 1 ไม่ถูกบันทึกลงในภาพที่สองค่ะ
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#24

Post by snasui »

:D ข้อมูลในวงกลมในภาพยังไม่ถูกเลือก ถ้าจะจับภาพแทนเขียนข้อความ ควรจับให้มีการเลือกข้อมูลทีจำเป็นมาด้วย ไม่เช่นนั้นเขียนแจ้งมาเลยว่า Control ใดเลือกหรือคีย์ใด ข้อมูลพวกนี้เป็นสิ่งจำเป็น ผมจะทดสอบตามนั้นทันทีไม่ต้องใช้เวลานาน
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#25

Post by Benmore »

ขอโทษด้วยค่ะน่าจะดึงผิดรูป
:ard: :ard: :ard:
You do not have the required permissions to view the files attached to this post.
User avatar
snasui
Site Admin
Site Admin
Posts: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#26

Post by snasui »

:D เรียงลำดับ Code ไม่ถูกต้องครับ

ตัวอย่างการเรียงลำดับ Code ควรจะเป็นด้านล่าง

Code: Select all

Private Sub btsave_Click()
    On Error Resume Next
    If TextBox1 = "" Or TextBox3 = "" Then
        MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅãËé¤Ãº¶éǹ"
        Exit Sub
    End If
    Dim emptyRow As Integer
    Dim ct As Object
    Dim strTb1 As Variant
    Dim strTb3 As Variant
    Sheet9.Activate
    emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
    For Each ct In Me.Frame2.Controls
        If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
            Cells(emptyRow, 7).Value = ct.Caption
            Exit For
        End If
    Next ct
    For Each ct In Me.Frame5.Controls
'Other code
สังเกตตัวแปรที่จะกำหนดค่าบรรทัดจะต้องกำหนดเอาไว้ก่อนที่จะนำข้อมูลไปวาง

ควรจะเอา On Error Resume Next ออกเสียก่อนแล้วทำการ Debug จะได้ทราบได้เองเบื้องต้นว่าผิดพลาดหรือไม่อย่างไรครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#27

Post by Benmore »

ลองปรับโค้ดตามแล้วไม่เกิดข้อผิดพลาดค่ะแต่ข้อมูลที่เลือกใน option button ไม่ถูกบันทึกลงในชีท 6 ค่ะ

Code: Select all

Private Sub btsave_Click()
'On Error Resume Next
 If TextBox1 = "" Or TextBox3 = "" Then
 MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅãËé¤Ãº¶éǹ"
Exit Sub
 End If
    Dim emptyRow As Integer
    Dim ct As Object
    Dim strTb1 As Variant
    Dim strTb3 As Variant
    Sheet9.Activate
    emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
    For Each ct In Me.Frame2.Controls
        If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
            Cells(emptyRow, 7).Value = ct.Caption
            Exit For
        End If
    Next ct
    For Each ct In Me.Frame5.Controls
 If VBA.Left(ct.Name, 4) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 8).Value = ct.Caption
 Exit For
 End If
Next ct
emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
'emptyRow = WorksheetFunction.Count("A3:A10000") + 1
If emptyRow = 0 Then
 emptyRow = 2
Else
 emptyRow = emptyRow + 2
 Sheet9.Activate
 strTb1 = Split(TextBox1.Text, vbCrLf)
strTb3 = TextBox3.Text & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = Split(strTb3, vbCrLf)
Cells(emptyRow, 1).Value = VBA.Mid(strTb1(0), InStr(strTb1(0), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 2).Value = VBA.Mid(strTb1(1), InStr(strTb1(1), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 3).Value = VBA.Mid(strTb1(2), InStr(strTb1(2), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 4).Value = VBA.Mid(strTb1(3), InStr(strTb1(3), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 6).Value = strTb3(0) & "," & strTb3(1) & "," & strTb3(2) & vbCrLf & strTb3(3) & "," & strTb3(4) & "," & strTb3(5) 'TextBox3.Value
'Cells(emptyRow, 7).Value = OptionButton
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
 MsgBox "ºÑ¹·Ö¡¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
Unload Me
 UserForm1.Show
End If
'Sheet1.Activate
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: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#28

Post by snasui »

:D Code ตามโพสต์ #27 เกี่ยวกับ Sheet9 ไม่เกี่ยวกับ Sheet6 ลองทบทวนดูอีกรอบครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#29

Post by Benmore »

ชีท9 ค่ะ
มันก็ไม่แสดงค่ะ
User avatar
snasui
Site Admin
Site Admin
Posts: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#30

Post by snasui »

:D ไฟล์ที่แนบมาล่าสุดยังไม่ปรับ Code เพื่อให้นำค่าใน Option Button ไปวาง ดูรูปประกอบครับ
You do not have the required permissions to view the files attached to this post.
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#31

Post by Benmore »

ไฟล์แนบที่แก้ไขโค้ดแล้วรันไม่ได้ตามที่ต้องการค่ะ

Code: Select all

'Save
Private Sub btsave_Click()
On Error Resume Next
 If TextBox1 = "" Or TextBox3 = "" Then
 MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅãËé¤Ãº¶éǹ"
Exit Sub
 End If
Dim emptyRow As Integer
Dim ct As Object
Dim strTb1 As Variant
Dim strTb3 As Variant
For Each ct In Me.Frame2.Controls
 If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 7).Value = ct.Caption
 Exit For
 End If
Next ct
For Each ct In Me.Frame5.Controls
 If VBA.Left(ct.Name, 4) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 8).Value = ct.Caption
 Exit For
 End If
Next ct
emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
'emptyRow = WorksheetFunction.Count("A3:A10000") + 1
If emptyRow = 0 Then
 emptyRow = 2
Else
 emptyRow = emptyRow + 2
 Sheet9.Activate
 strTb1 = Split(TextBox1.Text, vbCrLf)
strTb3 = TextBox3.Text & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = Split(strTb3, vbCrLf)
Cells(emptyRow, 1).Value = VBA.Mid(strTb1(0), InStr(strTb1(0), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 2).Value = VBA.Mid(strTb1(1), InStr(strTb1(1), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 3).Value = VBA.Mid(strTb1(2), InStr(strTb1(2), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 4).Value = VBA.Mid(strTb1(3), InStr(strTb1(3), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 6).Value = strTb3(0) & "," & strTb3(1) & "," & strTb3(2) & vbCrLf & strTb3(3) & "," & strTb3(4) & "," & strTb3(5) 'TextBox3.Value
'Cells(emptyRow, 7).Value = OptionButton
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
 MsgBox "ºÑ¹·Ö¡¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
Unload Me
 UserForm1.Show
End If
Sheet1.Activate
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: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#32

Post by snasui »

Benmore wrote:ไฟล์แนบที่แก้ไขโค้ดแล้วรันไม่ได้ตามที่ต้องการค่ะ

Code: Select all

'Save
Private Sub btsave_Click()
On Error Resume Next
 If TextBox1 = "" Or TextBox3 = "" Then
 MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅãËé¤Ãº¶éǹ"
Exit Sub
 End If
Dim emptyRow As Integer
Dim ct As Object
Dim strTb1 As Variant
Dim strTb3 As Variant
For Each ct In Me.Frame2.Controls
 If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 7).Value = ct.Caption
 Exit For
 End If
Next ct
For Each ct In Me.Frame5.Controls
 If VBA.Left(ct.Name, 4) = "Opt" And ct.Value = True Then
 Debug.Print ct.Name
 Cells(emptyRow, 8).Value = ct.Caption
 Exit For
 End If
Next ct
emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
'emptyRow = WorksheetFunction.Count("A3:A10000") + 1
If emptyRow = 0 Then
 emptyRow = 2
Else
 emptyRow = emptyRow + 2
 Sheet9.Activate
 strTb1 = Split(TextBox1.Text, vbCrLf)
strTb3 = TextBox3.Text & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = Split(strTb3, vbCrLf)
Cells(emptyRow, 1).Value = VBA.Mid(strTb1(0), InStr(strTb1(0), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 2).Value = VBA.Mid(strTb1(1), InStr(strTb1(1), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 3).Value = VBA.Mid(strTb1(2), InStr(strTb1(2), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 4).Value = VBA.Mid(strTb1(3), InStr(strTb1(3), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 6).Value = strTb3(0) & "," & strTb3(1) & "," & strTb3(2) & vbCrLf & strTb3(3) & "," & strTb3(4) & "," & strTb3(5) 'TextBox3.Value
'Cells(emptyRow, 7).Value = OptionButton
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
 MsgBox "ºÑ¹·Ö¡¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
Unload Me
 UserForm1.Show
End If
Sheet1.Activate
End Sub
:D Code ที่แนบมาไม่เป็นไปตามที่ผมตอบไปตามโพสต์ #26 ตามที่ยกมาด้านล่างนี้ครับ :ard:
snasui wrote::D เรียงลำดับ Code ไม่ถูกต้องครับ

ตัวอย่างการเรียงลำดับ Code ควรจะเป็นด้านล่าง

Code: Select all

Private Sub btsave_Click()
    On Error Resume Next
    If TextBox1 = "" Or TextBox3 = "" Then
        MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅãËé¤Ãº¶éǹ"
        Exit Sub
    End If
    Dim emptyRow As Integer
    Dim ct As Object
    Dim strTb1 As Variant
    Dim strTb3 As Variant
    Sheet9.Activate
    emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
    For Each ct In Me.Frame2.Controls
        If VBA.Left(ct.Name, 3) = "Opt" And ct.Value = True Then
            Cells(emptyRow, 7).Value = ct.Caption
            Exit For
        End If
    Next ct
    For Each ct In Me.Frame5.Controls
'Other code
สังเกตตัวแปรที่จะกำหนดค่าบรรทัดจะต้องกำหนดเอาไว้ก่อนที่จะนำข้อมูลไปวาง

ควรจะเอา On Error Resume Next ออกเสียก่อนแล้วทำการ Debug จะได้ทราบได้เองเบื้องต้นว่าผิดพลาดหรือไม่อย่างไรครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#33

Post by Benmore »

รบกวนตรวจสอบโค้ดให้หน่อยค่ะ พอดีเวลาค้นหาข้อมูลด้วยรหัสแล้วมันค้นหาไม่ได้ค่ะ

Code: Select all

Private Sub btsearch1_Click()
On Error Resume Next
   Dim found As Boolean
   Dim txt As String
   Dim r As Range
    Dim chkDate As Date
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
    If Right(r.Value, 3) = Right(txtsearch1.Text, 3) Or r.Offset(0, 4).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
            MsgBox "¡ÃسÒãÊè¢éÍÁÙÅà»ç¹µÑÇàÅ¢"
            Exit Sub
        End If
        If Err.Number = 91 Then
        TextBox1.RowSource = "txtsearch1.Text"
  TextBox7.Value = ""
    TextBox8.Value = ""
    TextBox9.Value = ""
    TextBox10.Value = ""
      TextBox11.Value = ""
         TextBox16.Value = ""
            TextBox17.Value = ""
        TextBox12.Value = ""
          TextBox13.Value = ""
    'MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
 TextBox7.Value = Cells(nRow, 1)
TextBox8.Value = Cells(nRow, 2)
    TextBox9.Value = Cells(nRow, 3)
    TextBox10.Value = Cells(nRow, 4)
      TextBox11.Value = Cells(nRow, 6)
      TextBox16.Value = Cells(nRow, 7)
      TextBox17.Value = Cells(nRow, 8)
        TextBox12.Value = Cells(nRow, 9)
          TextBox13.Value = Cells(nRow, 10)
     Exit Sub
     Else
       MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
    Sheet1.Activate
End Sub
Uniform_EGAS(Ex).zip
You do not have the required permissions to view the files attached to this post.
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#34

Post by Benmore »

คำถามด้านบนทำได้แล้วรบกวนดูโค้ดบันทึกข้อมูลหน่อยค่ะ
เมื่อเลือกข้อมูลใน optionbutton แล้วข้อมูลไม่ถูกบันทึกลงในชีท 9 "การเบิก" ค่ะ

Code: Select all

Private Sub btsave_Click()
'On Error Resume Next
 If TextBox1 = "" Or TextBox3 = "" Then
 MsgBox "กรุณากรอกข้อมูลให้ครบถ้วน"
Exit Sub
 End If
Dim emptyRow As Integer
Dim ct As Object
Dim strTb1 As Variant
Dim strTb3 As Variant
opt = OptionButton1.Value Or OptionButton2.Value
emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
'emptyRow = WorksheetFunction.Count("A3:A10000") + 1
If emptyRow = 0 Then
 emptyRow = 2
Else
 emptyRow = emptyRow + 2
 Sheet9.Activate
 strTb1 = Split(TextBox1.Text, vbCrLf)
strTb3 = TextBox3.Text & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = strTb3 & vbCrLf
strTb3 = Split(strTb3, vbCrLf)
Cells(emptyRow, 1).Value = VBA.Mid(strTb1(0), InStr(strTb1(0), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 2).Value = VBA.Mid(strTb1(1), InStr(strTb1(1), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 3).Value = VBA.Mid(strTb1(2), InStr(strTb1(2), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 4).Value = VBA.Mid(strTb1(3), InStr(strTb1(3), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 6).Value = strTb3(0) & "," & strTb3(1) & "," & strTb3(2)  'TextBox3.Value
Cells(emptyRow, 7).Value = strTb3(3) & "," & strTb3(4) & "," & strTb3(5)
Cells(emptyRow, 8).Value = strTb3(6) & "," & strTb3(7)
If OptionButton1.Value = True Then
        Cells(CurrentRow, 10).Value = "มารับแล้ว"
    ElseIf OptionButton2.Value = True Then
        Cells(CurrentRow, 10).Value = "ไม่ได้มารับ"
        ElseIf OptionButton3.Value = True Then
        Cells(CurrentRow, 10).Value = TextBox15.Value
    End If
    If OptionButton4.Value = True Then
        Cells(CurrentRow, 9).Value = "ชุดหดและเก่าตามสภาพ"
    ElseIf OptionButton5.Value = True Then
        Cells(CurrentRow, 9).Value = "ชุดเปื่อยขาด เนื่องจากการซัก"
          ElseIf OptionButton6.Value = True Then
        Cells(CurrentRow, 9).Value = "ชุดขาดตามรอยตะเข็บ"
         ElseIf OptionButton7.Value = True Then
        Cells(CurrentRow, 9).Value = "เดินทางไปต่างจังหวัด/ต่างประเทศ"
        ElseIf OptionButton8.Value = True Then
        Cells(CurrentRow, 9).Value = TextBox2.Value
    End If
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
 MsgBox "บันทึกข้อมูลเรียบร้อยแล้ว"
Unload Me
 UserForm1.Show
End If
'Sheet1.Activate
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: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#35

Post by snasui »

:D โปรแกรมฟ้อง Error ตรงไหน อย่างไร ช่วย Debug และแจ้งมาด้วยครับ

จากที่ดู Code ไม่ทราบว่าตัวแปร CurrentRow มีค่าเท่ากับค่าใด กำหนดค่าไว้ที่บรรทัดใดครับ

ผมเข้าใจว่าเป็นค่าเดียวกับตัวแปร emptyRow หากเป็นค่าเดียวกันให้ใช้ตัวแปร emptyRow ได้เลยครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#36

Post by Benmore »

ทำได้แล้วขอบคุณมากกกกกกกกกกกกกกกค่ะ :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp:
สอบถามเพิ่มเติมค่ะ ถ้าต้องการให้ textbox กรอกข้อมูลได้เฉพาะวันทีีต้องเขียนโค้ดแบบไหนค่ะ
:arrow: Userform2 ตรงเฟรมสถานะในการส่งซ่อมค่ะ
You do not have the required permissions to view the files attached to this post.
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#37

Post by Benmore »

:?: :?: :?: :shock: :shock: :shock:
User avatar
snasui
Site Admin
Site Admin
Posts: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#38

Post by snasui »

Benmore wrote:ทำได้แล้วขอบคุณมากกกกกกกกกกกกกกกค่ะ :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp: :cp:
สอบถามเพิ่มเติมค่ะ ถ้าต้องการให้ textbox กรอกข้อมูลได้เฉพาะวันทีีต้องเขียนโค้ดแบบไหนค่ะ
:arrow: Userform2 ตรงเฟรมสถานะในการส่งซ่อมค่ะ
:D การให้กรอกวันที่เองมีความยุ่งยากในการตรวจสอบเพราะสามารถจะคีย์เป็นตัวเลขวันแล้วตามด้วยเดือนเป็นข้อความ หากแยกช่องเป็น วัน เดือน ปี แล้วเช็คแต่ละช่องว่าเป็นไปตามที่กำหนดหรือไม่จะง่ายกว่าครับ
Benmore wrote: :?: :?: :?: :shock: :shock: :shock:


ฟอรัมนี้ไม่อนุญาตให้ดันกระทู้โดยไม่มีการโพสต์ข้อความอื่นใดเพิ่มเติม การตอบปัญหาขึ้นอยู่กับเวลาว่างของผู้ตอบ ขออภัยในความไม่สะดวกครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

Re: บันทึกข้อมูล

#39

Post by Benmore »

ตรงนี้แก้ไขได้แล้วค่ะ รบกวนดูโค้ด Delete ให้ด้วยค่ะ
ถ้าต้องการลบข้อมูลที่ค้นหามาต้องแก้ไขโค้ดเพิ่มตรงไหนบ้างค่ะ
โค้ดค้นหาข้อมูลจากชีทการเบิก แล้วก็ให้ลบออกจากชีทการเบิกค่ะ
:arrow: Userform1

Code: Select all

Private Sub CommandButton6_Click()
 Dim id As String
        Dim rowselect As String
        If TextBox7.Text = "" Then
        MsgBox ("กรุณาเลือกข้อมูล")
        Else
        id = TextBox7.Text
        rowselect = WorksheetFunction.Match(id, Sheet6.Range("A1:A300"), 0)
        Rows(rowselect).Select
       Rows(rowselect).EntireRow.Delete
        End If
        Unload Me
        UserForm1.Show
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: 30736
Joined: Sun Jan 24, 2010 12:33 pm
Location: Songkhla, Thailand
Excel Ver: 2010, 365
Contact:

Re: บันทึกข้อมูล

#40

Post by snasui »

:D ลบชีตการเบิก เปลี่ยน Sheet6 เป็น Sheet9 ครับ

rowselect = WorksheetFunction.Match(id, Sheet9.Range("A1:A300"), 0)
Post Reply