: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

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

#1

Post by Benmore »

ขอสอบถามหน่อยค่ะ พอดีตอนนี้ติดปัญหาในการบันทึกข้อมูลค่ะ
เมื่อบันทึกข้อมูลลงไป ข้อมูลจะถูกบันทึกลงในชีท excel แทนที่กันไปเรื่อยๆไม่บันทึกลงมาเรื่อยๆค่ะ ต้องแก้ตรงไหนค่ะ

Code: Select all

'Save
Private Sub btsave_Click()
On Error Resume Next
Dim emptyRow As Integer
Dim strTb1 As Variant
Dim strTb3 As Variant
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 = VBA.Mid(strTb3(6), InStr(strTb3(6), ":") + 1) & vbCrLf & VBA.Mid(strTb3(7), InStr(strTb3(7), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
   MsgBox "บันทึกข้อมูลเรียบร้อยแล้ว"
     Unload Me
     Sheet1.Activate
End If
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: บันทึกข้อมูล

#2

Post by snasui »

:D ช่วยกลับไปแจ้งผลในกระทู้เหล่านี้ก่อนครับ search.php?keywords=&terms=all&author=B ... mit=Search
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#3

Post by Benmore »

Benmore wrote:ขอสอบถามหน่อยค่ะ พอดีตอนนี้ติดปัญหาในการบันทึกข้อมูลค่ะ
เมื่อบันทึกข้อมูลลงไป ข้อมูลจะถูกบันทึกลงในชีท excel แทนที่กันไปเรื่อยๆไม่บันทึกลงมาเรื่อยๆค่ะ ต้องแก้ตรงไหนค่ะ

Code: Select all

'Save
Private Sub btsave_Click()
On Error Resume Next
Dim emptyRow As Integer
Dim strTb1 As Variant
Dim strTb3 As Variant
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 = VBA.Mid(strTb3(6), InStr(strTb3(6), ":") + 1) & vbCrLf & VBA.Mid(strTb3(7), InStr(strTb3(7), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
   MsgBox "บันทึกข้อมูลเรียบร้อยแล้ว"
     Unload Me
     Sheet1.Activate
End If
End Sub
รบกวนขอผู้รู้ช่วยหน่อยค่ะ
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: บันทึกข้อมูล

#4

Post by snasui »

:D ตัวอย่างการปรับ Code ครับ emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#5

Post by Benmore »

snasui wrote::D ตัวอย่างการปรับ Code ครับ emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
ตรงบันทึกทำได้แล้วขอบคุณมากค่ะ (ติดตรงนี้มานานมากกกกกกก55555)
ขอสอบถามเพิ่มเติ่มค่ะ
ถ้าต้องการให้เลือกข้อมูลในวงกลมแล้วไม่ให้ข้อมูลแสดงใน textbox3 แต่เมื่อบันทึกข้อมูลลงไปให้ข้อมูลถูกบันทึกในชีทตามที่กำหนดต้องแก้โค้ดเพิ่มตรงไหนบ้างค่ะ
รูป.png
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: บันทึกข้อมูล

#6

Post by snasui »

:D ได้กลับไปแจ้งผลตามที่ผมแจ้งไปในความเห็น #2 แล้วหรือไม่ ผมพบว่ามีการแจ้งแค่ไม่กี่กระทู้จากกระทู้ทั้งหมด

กรณีติดขัดตรงไหน อย่างไร หรือรอทดสอบ หรือเปลี่ยนวิธีการ หรือด้วยเหตุอื่น กรุณาแจ้งเอาไว้ด้วยจะได้ทราบว่ากำลังดำเนินการครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#7

Post by Benmore »

Benmore wrote:
snasui wrote::D ตัวอย่างการปรับ Code ครับ emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
ตรงบันทึกทำได้แล้วขอบคุณมากค่ะ (ติดตรงนี้มานานมากกกกกกก55555)
ขอสอบถามเพิ่มเติ่มค่ะ
ถ้าต้องการให้เลือกข้อมูลในวงกลมแล้วไม่ให้ข้อมูลแสดงใน textbox3 แต่เมื่อบันทึกข้อมูลลงไปให้ข้อมูลถูกบันทึกในชีทตามที่กำหนดต้องแก้โค้ดเพิ่มตรงไหนบ้างค่ะ
รูป.png
รบกวนขอผู้รู้ช่วยหน่อยค่ะ
kio2002
Member
Member
Posts: 177
Joined: Thu Sep 20, 2012 8:40 am

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

#8

Post by kio2002 »

กระทู้ของคุณ benmore เยอะมากครับ ผมตามไม่ทันเลย
Project ของคุณ benmore ที่กำลังทำอยู่ ถือว่าค่อนข้างซับซ้อนครับ ต้องมีพื้นฐานและความเข้าใจและชำนาญเกี่ยวกับ VBA เป็นอย่างมาก
ก่อนหน้านี้ ผมมี Project ยากๆที่ผมเคยลองดันตัวเองแล้ว1ครั้ง แต่ไปไม่รอด เพราะยังมีความเข้าใจเกี่ยวกับ VBA น้อย
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#9

Post by Benmore »

kio2002 wrote:กระทู้ของคุณ benmore เยอะมากครับ ผมตามไม่ทันเลย
Project ของคุณ benmore ที่กำลังทำอยู่ ถือว่าค่อนข้างซับซ้อนครับ ต้องมีพื้นฐานและความเข้าใจและชำนาญเกี่ยวกับ VBA เป็นอย่างมาก
ก่อนหน้านี้ ผมมี Project ยากๆที่ผมเคยลองดันตัวเองแล้ว1ครั้ง แต่ไปไม่รอด เพราะยังมีความเข้าใจเกี่ยวกับ VBA น้อย
พอดีว่ากระทู้อื่นทำได้หมดแล้วค่ะ เลยรายงานผลให้ผู้ที่ตอบให้ค่ะว่าทำได้แล้วค่ะ
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: บันทึกข้อมูล

#10

Post by snasui »

Benmore wrote:
snasui wrote::D ตัวอย่างการปรับ Code ครับ emptyRow = WorksheetFunction.CountA(Sheet9.Range("A3:A10000")) + 1
ตรงบันทึกทำได้แล้วขอบคุณมากค่ะ (ติดตรงนี้มานานมากกกกกกก55555)
ขอสอบถามเพิ่มเติ่มค่ะ
ถ้าต้องการให้เลือกข้อมูลในวงกลมแล้วไม่ให้ข้อมูลแสดงใน textbox3 แต่เมื่อบันทึกข้อมูลลงไปให้ข้อมูลถูกบันทึกในชีทตามที่กำหนดต้องแก้โค้ดเพิ่มตรงไหนบ้างค่ะ
รูป.png
:D ขั้นตอนการเลือกแล้วไม่เพิ่มใน Textbox3 ไม่ควรจะเป็นปัญหาเพราะไปยกเลิก Change Event เมื่อเลือกไม่ให้ดำเนินการใด ๆ ได้ ปัญหาน่าจะอยู่ที่การบันทักข้อมูลลงในชีตแล้วให้ข้อมูลใน Control เหล่าสนั้นนำไปวางด้วย ได้เขียนการทำงานส่วนนี้เพิ่มเข้าไปแล้วหรือไม่ ติดขัดบรรทัดใด หากยังไม่เขียน กุณาเขียนมาเองก่อน ถามเฉพาะที่ติดปัญหา แจ้งตัวอย่างผลลัพธ์ที่ต้องการเอาไว้ด้วยว่าหากบันทึกถูกต้องจะแสดงรายการที่ชีตใด เซลล์ใด ด้วยค่าเท่าใด จะได้สะดวกในการทดสอบครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#11

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 strTb1 As Variant
Dim strTb3 As Variant
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, 7).Value = VBA.Mid(strTb3(6), InStr(strTb3(6), ":") + 1) & vbCrLf & VBA.Mid(strTb3(7), InStr(strTb3(7), ":") + 1) 'TextBox1.Value
 'Cells(emptyRow, 8).Value = VBA.Mid(strTb3(8), InStr(strTb3(8), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
   MsgBox "บันทึกข้อมูลเรียบร้อย"
     Unload Me
   UserForm1.Show
End If
Sheet1.Activate
End Sub
ลองแก้โค้ดเองแล้วค่ะก็ยังทำไม่ได้ค่ะ รบกวนสอบถามว่าต้องแก้ไขตรงไหนเพิ่มค่ะ
Uniform_EGAS(Ex).xlsm
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: บันทึกข้อมูล

#12

Post by snasui »

:D ตัวอย่างการ Loop Option Button ทีมีการเลือกแล้ววางลงในชีตครับ

Code: Select all

'Other code
dim ct as object
'Other code
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
ปรับให้ใช้ได้กับ Option Button ตัวสุดท้ายที่เป็นตัวเลือกอื่น ๆ ที่ไม่ได้นำ Caption ของ Option Button มาใช้แต่เป็นการตำค่าใน TextBox ที่ผู้ใช้งานคีย์เข้าไปเองมาใช้แทนครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#13

Post by Benmore »

snasui wrote::D ตัวอย่างการ Loop Option Button ทีมีการเลือกแล้ววางลงในชีตครับ

Code: Select all

'Other code
dim ct as object
'Other code
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
ปรับให้ใช้ได้กับ Option Button ตัวสุดท้ายที่เป็นตัวเลือกอื่น ๆ ที่ไม่ได้นำ Caption ของ Option Button มาใช้แต่เป็นการตำค่าใน TextBox ที่ผู้ใช้งานคีย์เข้าไปเองมาใช้แทนครับ

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, 7).Value = VBA.Mid(strTb3(6), InStr(strTb3(6), ":") + 1) & vbCrLf & VBA.Mid(strTb3(7), InStr(strTb3(7), ":") + 1) 'TextBox1.Value
 'Cells(emptyRow, 8).Value = VBA.Mid(strTb3(8), InStr(strTb3(8), ":") + 1) 'TextBox1.Value
Cells(emptyRow, 5).Value = comday.Value & "/" & commonth.Value & "/" & comyear.Value
   MsgBox "บันทึกข้อมูลเรียบร้อยแล้ว"
     Unload Me
   UserForm1.Show
End If
Sheet1.Activate
End Sub{code]
ปรับโค้ดแล้วก็ยังไม่ได้ค้ะ ต้องปรับตรงไหนเพิ่มค่ะ
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: บันทึกข้อมูล

#14

Post by snasui »

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

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

#15

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: บันทึกข้อมูล

#16

Post by snasui »

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

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

#17

Post by Benmore »

snasui wrote::D กรุณาอ่านที่ผมโพสต์และแจ้งมาตามนั้นให้ครบถ้วนทุกข้อความที่ผมเขียนแจ้งไป โดยเขียนมาในช่องความเห็นนี้ด้วยครับ
:arrow: ให้เลือกข้อมูลใน option button แล้วข้อมูลที่เราเลือกก็จะถูกบันทึกลงในชีทการเบิกในคอลลัมตามที่เราต้องการค่ะ
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: บันทึกข้อมูล

#18

Post by snasui »

:D อ่านโพสต์ #14 ซ้ำอีกรอบแล้วตอบมาให้ครบตามที่ผมแจ้งไปครับ
Benmore
Bronze
Bronze
Posts: 254
Joined: Tue Sep 05, 2017 9:51 am

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

#19

Post by Benmore »

snasui wrote::D กรุณาอ่านที่ผมโพสต์และแจ้งมาตามนั้นให้ครบถ้วนทุกข้อความที่ผมเขียนแจ้งไป โดยเขียนมาในช่องความเห็นนี้ด้วยครับ

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

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
:arrow: เมื่อเลือกข้อมูลใน option button ในส่วนของ Reason แล้วพอกดปุ่มบันทึกให้ข้อมูลถูกบันทึกลงในคอลลัมน์ Reason ในชีทการเบิกค่ะ
:arrow: เมื่อเลือกข้อมูลใน option button ในส่วนของ Status แล้วพอกดปุ่มบันทึกให้ข้อมูลถูกบันทึกลงในคอลลัมน์ Status ในชีทการเบิกค่ะ
:ard:
ปัญหาที่แจ้งอยู่ที่ UserForm1 ค่ะ
:aru:
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: บันทึกข้อมูล

#20

Post by snasui »

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