Page 1 of 1

เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box

Posted: Tue Jun 02, 2020 11:15 am
by wisitsakbenz
เรียนสอบถามอาจารย์ครับ

เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box ด้วย
ต้องปรับ Code อย่างไรบ้างครับ ขอบคุณครับ

Code: Select all

Sub Nextdata()
If Sheets("Data").Cells(ActiveCell.Row + 1, 1) = Empty Then
    MsgBox "Can not go to the next data. ... this last one."
    GoTo NextStep
End If

    nextRow = ActiveCell.Row + 1
    Cells(nextRow, 1).Activate
    Sheets("Input").Range("C4").Value = Sheets("Data").Cells(nextRow, 2)
    Sheets("Input").Range("C6").Value = Sheets("Data").Cells(nextRow, 3)
    Sheets("Input").Range("C8").Value = Sheets("Data").Cells(nextRow, 4)
    Sheets("Input").Range("C10").Value = Sheets("Data").Cells(nextRow, 5)

NextStep:

End Sub


Sub Previousdata()

If Sheets("Data").Cells(ActiveCell.Row - 1, 1) = "ON" Then
    MsgBox "Can not go to the previous data. ... this last one."
    GoTo NextStep
End If

    nextRow = ActiveCell.Row - 1
    Cells(nextRow, 1).Activate
    Sheets("Input").Range("C4").Value = Sheets("Data").Cells(nextRow, 2)
    Sheets("Input").Range("C6").Value = Sheets("Data").Cells(nextRow, 3)
    Sheets("Input").Range("C8").Value = Sheets("Data").Cells(nextRow, 4)
    Sheets("Input").Range("C10").Value = Sheets("Data").Cells(nextRow, 5)

NextStep:

End Sub

Re: เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box

Posted: Tue Jun 02, 2020 8:51 pm
by snasui
:D ช่วยแจ้งขั้นตอนการทดสอบให้เห็นสภาพปัจจุบันว่าเป็นอย่างไร พร้อมทั้งระบุถึงค่าที่ต้องการให้เป็น จะได้สะดวกในการทำความเข้าใจครับ

Re: เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box

Posted: Thu Jun 04, 2020 8:02 am
by wisitsakbenz
เรียน อาจารย์

ขั้นตอนคือ กดคลิกปุ่ม Previous หรือ Next อยากให้โชว์ค่า Sex เป็น Male หรือ Female ด้วย

รบกวนอาจารย์ด้วยครับ ขอบคุณครับ

Re: เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box

Posted: Sat Jun 06, 2020 8:38 am
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

'Other code
Sheets("Input").Range("C8").Value = Sheets("Data").Cells(nextRow, 4)
If Sheets("Data").Cells(nextRow, 5) = "Male" Then
    Sheets("Input").OLEObjects("OptionButton1").Object.Value = True
    Sheets("Input").OLEObjects("OptionButton2").Object.Value = False
ElseIf Sheets("Data").Cells(nextRow, 5) = "Female" Then
    Sheets("Input").OLEObjects("OptionButton1").Object.Value = False
    Sheets("Input").OLEObjects("OptionButton2").Object.Value = True
Else
    Sheets("Input").OLEObjects("OptionButton1").Object.Value = False
    Sheets("Input").OLEObjects("OptionButton2").Object.Value = False
End If
NextStep:
'Other code

Re: เวลากด Next หรือ Previous ต้องการคืนค่าให้ option Box

Posted: Mon Jun 08, 2020 8:31 am
by wisitsakbenz
เรียนอาจารย์ snasui

ได้แล้วครับ ขอบคุณอาจารย์มากเลยครับ