หนูขอสอบถามค่ะ หนูใช้ userform 2 แบบ แต่หนูอยากให้ userform ที่ 2 มีข้อมูลบรรทัดเดียวกันกับแบบที่ 1 ค่ะ
Posted: Mon Apr 19, 2021 10:31 am
หนูควรแก้ไขยังไงดีคะ ขอบคุณค่ะ
แบบที่ 1
Private Sub cmd_บันทึก_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Range("A" & last_row + 1).Value = txt_ผู้ใช้งาน.Value
Range("B" & last_row + 1).Value = txt_รหัสนักศึกษา.Value
Range("C" & last_row + 1).Value = txt_วันที่.Value
Range("D" & last_row + 1).Value = txt_เวลา.Value
'Clear
txt_ผู้ใช้งาน.Value = ""
txt_รหัสนักศึกษา.Value = ""
Call date_data
Call time_data
End Sub
แบบที่ 2
Private Sub cmd_บันทึก1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Range("H" & last_row + 1).Value = txt_จำนวน1.Value
Range("I" & last_row + 1).Value = cb_หน่วย1.Value
Range("G" & last_row + 1).Value = cb_รหัสวัสดุ1.Value
If Check_ยืม.Value = True Then
Range("E" & last_row + 1).Value = "ยืม"
End If
If Check_คืน.Value = True Then
Range("E" & last_row + 1).Value = "คืน"
End If
If opt_RM.Value = True Then
Range("F" & last_row + 1).Value = "RawMaterial"
End If
If opt_AS.Value = True Then
Range("F" & last_row + 1).Value = "Assemby"
End If
If opt_FG.Value = True Then
Range("F" & last_row + 1).Value = "FinishGood"
End If
'Clear data
txt_จำนวน1.Value = ""
cb_หน่วย1.Value = ""
cb_รหัสวัสดุ1.Value = ""
End Sub
แบบที่ 1
Private Sub cmd_บันทึก_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Range("A" & last_row + 1).Value = txt_ผู้ใช้งาน.Value
Range("B" & last_row + 1).Value = txt_รหัสนักศึกษา.Value
Range("C" & last_row + 1).Value = txt_วันที่.Value
Range("D" & last_row + 1).Value = txt_เวลา.Value
'Clear
txt_ผู้ใช้งาน.Value = ""
txt_รหัสนักศึกษา.Value = ""
Call date_data
Call time_data
End Sub
แบบที่ 2
Private Sub cmd_บันทึก1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Range("H" & last_row + 1).Value = txt_จำนวน1.Value
Range("I" & last_row + 1).Value = cb_หน่วย1.Value
Range("G" & last_row + 1).Value = cb_รหัสวัสดุ1.Value
If Check_ยืม.Value = True Then
Range("E" & last_row + 1).Value = "ยืม"
End If
If Check_คืน.Value = True Then
Range("E" & last_row + 1).Value = "คืน"
End If
If opt_RM.Value = True Then
Range("F" & last_row + 1).Value = "RawMaterial"
End If
If opt_AS.Value = True Then
Range("F" & last_row + 1).Value = "Assemby"
End If
If opt_FG.Value = True Then
Range("F" & last_row + 1).Value = "FinishGood"
End If
'Clear data
txt_จำนวน1.Value = ""
cb_หน่วย1.Value = ""
cb_รหัสวัสดุ1.Value = ""
End Sub