Page 1 of 1

Macto : ต้องการแก้ไขข้อมูลแพทย์

Posted: Thu Feb 25, 2021 1:41 pm
by wisitsakbenz
เรียน อาจารย์

หลังจากค้นหาข้อมูลด้วย HN แล้ว ต้องการแก้ไขข้อมูลแพทย์ โดยคลิกที่ Row1,2,3,...หลังจากนั้นเปลี่ยนชื่อแพทย์ที่ช่อง C5 แล้วกด Save ข้อมูลแพทย์จะถูกแก้ที่ Row 1 เท่านั้น อยากให้คลิกที่ Row ไหนใน List Box ข้อมูลแพทย์ Row นั้นจะถูกแก้

ต้องปรับ Code อย่างไรครับ ขอบคุณครับ

Code: Select all

 
Private Sub CommandButton2_Click()

    'ActiveSheet.Unprotect "1234"

    Dim y As Long
    Dim x As Integer
    Dim z As Integer
    
        x = MsgBox("ยืนยันที่จะอัพเดทข้อมูล??", vbOKCancel, "แจ้งเตือน")
       If x = vbOK Then
        y = Worksheets("Data").Columns(2).Find(Sheets("Input").Range("H3").Value).Row
        
Sheets("Data").Cells(y, 2).Value = Sheets("Input").Range("C2").Value
Sheets("Data").Cells(y, 3).Value = Sheets("Input").Range("C3").Value
Sheets("Data").Cells(y, 4).Value = Sheets("Input").Range("C4").Value
Sheets("Data").Cells(y, 5).Value = Sheets("Input").Range("C5").Value

    z = MsgBox("แก้ไขข้อมูลเรียบร้อยแล้ว", vbOKOnly, "แจ้งเตือน")
        Else
        Sheets("Input").Select
    End If
    'Call Reset
    
End Sub

Re: Macto : ต้องการแก้ไขข้อมูลแพทย์

Posted: Thu Feb 25, 2021 10:42 pm
by puriwutpokin
ใช้เซล C1 มาช่วยครับ แล้ว ไม่ต้องการให้เห็นก็เปลี่ยนสิเป็นสีขาวดูครับตามนี้ ครับ

Code: Select all

Private Sub CommandButton2_Click()

    'ActiveSheet.Unprotect "1234"

    Dim y As Long
    Dim x As Integer
    Dim z As Integer
    
        x = MsgBox("ยืนยันที่จะอัพเดทข้อมูล??", vbOKCancel, "แจ้งเตือน")
       If x = vbOK Then
      y = Worksheets("Data").Columns(1).Find(Sheets("Input").Range("c1").Value).Row
        
Sheets("Data").Cells(y, 2).Value = Sheets("Input").Range("C2").Value
Sheets("Data").Cells(y, 3).Value = Sheets("Input").Range("C3").Value
Sheets("Data").Cells(y, 4).Value = Sheets("Input").Range("C4").Value
Sheets("Data").Cells(y, 5).Value = Sheets("Input").Range("C5").Value

    z = MsgBox("แก้ไขข้อมูลเรียบร้อยแล้ว", vbOKOnly, "แจ้งเตือน")
        Else
        Sheets("Input").Select
    End If
    'Call Reset
    
End Sub

Private Sub ListBox1_Click()
Dim say, lastrow As Long, a As Byte, i As Integer
On Error Resume Next
        i = Me.ListBox1.ListIndex
    If Me.ListBox1.Selected(i) = True Then
Sheets("Input").Range("C1").Value = Me.ListBox1.List(i, 0)
Sheets("Input").Range("C2").Value = Me.ListBox1.List(i, 1)
Sheets("Input").Range("C3").Value = Me.ListBox1.List(i, 2)
Sheets("Input").Range("C4").Value = Me.ListBox1.List(i, 3)
Sheets("Input").Range("C5").Value = Me.ListBox1.List(i, 4)
    End If
lastrow = Sheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Input").Activate
Sheets("Data").Range("A2:A" & lastrow).Find(What:=ListBox1.Value, LookIn:=xlValues, LookAt:=xlWhole).Activate


End Sub

Re: Macto : ต้องการแก้ไขข้อมูลแพทย์

Posted: Fri Feb 26, 2021 12:00 pm
by wisitsakbenz
เรียน อาจารย์ puriwutpokin
ได้แล้วครับ ขอบคุณมากครับ