Page 1 of 1

ต้องการให้เวลากดบันทึกแล้ว ลำดับที่ รันอัตโนมัติ

Posted: Fri Sep 11, 2020 3:54 pm
by thinatda

Code: Select all

lastrow = Worksheets("ÊÒÃÁҵðҹ").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 1).Value = TOrder.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 2).Value = TList.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 3).Value = TMolcular.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 4).Value = ComGrade.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 5).Value = TPurity.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 6).Value = TCasNo.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 7).Value = TBottle.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 8).Value = TLot.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 9).Value = ComCompany.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 10).Value = TSize.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 11).Value = TTemperature.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 12).Value = TInputday.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 13).Value = TOutputday.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 15).Value = TExpire.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 16).Value = TStatus.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 17).Value = ComType.Text
Worksheets("ÊÒÃÁҵðҹ").Cells(lastrow + 1, 18).Value = TCoa.Text

Dim i As Long
On Error Resume Next
i = Application.WorksheetFunction.CountA(Sheet1.Range("B:B"))
If i > 1 Then
Sheet1.Range("A" & i).Value = i - 1
End If

TOrder.Value = " "
TList.Value = " "
TMolcular.Value = " "
ComGrade.Value = " "
TPurity.Value = " "
TCasNo.Value = " "
TBottle.Value = " "
TLot.Value = " "
ComCompany.Value = " "
TSize.Value = " "
TTemperature.Value = " "
TInputday.Value = " "
TExpire.Value = " "
TStatus.Value = " "
ComType.Value = " "
TCoa.Value = " "

Re: ต้องการให้เวลากดบันทึกแล้ว ลำดับที่ รันอัตโนมัติ

Posted: Fri Sep 11, 2020 8:06 pm
by snasui
:D ตัวอย่างการปรับ Code ครับ

Code: Select all

'Other code
Dim i As Long
On Error Resume Next
i = Sheet1.Range("a1").CurrentRegion.Rows.Count
If i = 2 Then
    Sheet1.Range("A2").Value = 1
Else
    Sheet1.Range("A" & i).Value = i - 1
End If
'Other code

Re: ต้องการให้เวลากดบันทึกแล้ว ลำดับที่ รันอัตโนมัติ

Posted: Mon Sep 14, 2020 3:40 pm
by thinatda
snasui wrote: Fri Sep 11, 2020 8:06 pm :D ตัวอย่างการปรับ Code ครับ

Code: Select all

'Other code
Dim i As Long
On Error Resume Next
i = Sheet1.Range("a1").CurrentRegion.Rows.Count
If i = 2 Then
    Sheet1.Range("A2").Value = 1
Else
    Sheet1.Range("A" & i).Value = i - 1
End If
'Other code
ขอบคุณค่ะได้แล้วค่ะ