: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

หาสูตรการเก็บค่าของ Sheets ที่ Option Button เลือก

ฟอรัมถาม-ตอบปัญหาการใช้งาน 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

หาสูตรการเก็บค่าของ Sheets ที่ Option Button เลือก

#1

Post by Godtheking »

ผมอยากจะแทนค่าใน Set sh = ThisWorkbook.Sheets("Trim")
ให้ Trim เก็บค่าเอา Sheets จาก Option Button ถ้าเลือก PBP ให้ Trim เปลี่ยนเป็น PBP
ต้องเขียนโค้ดอย่างไงครับ

Code: Select all

    Dim sh As Worksheet
    Dim iRow As Long
    
        Set sh = ThisWorkbook.Sheets("Trim")

        If frmForm.txtRowNumber.Value = "" Then
            iRow = Sheets("Trim").Range("A" & Rows.Count).End(xlUp).Row + 1
        Else
            iRow = frmForm.txtRowNumber.Value
        End If
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: หาสูตรการเก็บค่าของ Sheets ที่ Option Button เลือก

#2

Post by snasui »

:D ตัวอย่างการปรับ Code ลองประยุกต์ใช้ดูครับ

Code: Select all

'Other code'
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(x)
'Other code
ในโอกาสถัดไปกรุณาระบุรายละเอียดให้ครบว่า Code อยู่ที่ Module ไหน ชื่อว่าอะไร อ่านกฎการใช้บอร์ดข้อ 5 ด้านบนประกอบ :roll: จะได้เข้าถึงปัญหาโดยไวครับ
Godtheking
Member
Member
Posts: 33
Joined: Thu Feb 23, 2023 7:02 am
Excel Ver: 2010,365

Re: หาสูตรการเก็บค่าของ Sheets ที่ Option Button เลือก

#3

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
 
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: หาสูตรการเก็บค่าของ Sheets ที่ Option Button เลือก

#4

Post by snasui »

:D ช่วยโพสต์ให้เป็นไปตามกฎการใช้บอร์ดข้อ 1 ด้านบน :aru: แล้วแจ้งมาใหม่ครับ
Post Reply