Chia sẻ với các bạn đoạn code của mình tích hợp thêm tắt screenupdating, khi getopenfilename nhấn cancel không bị lỗi runtime error và tìm last row.
Sub creat_files_based_on_a_template()
Dim template As Workbook
Dim duong_dan As String
Dim chi_nhanh As Range
Dim lr As Long
Application.ScreenUpdating = False
lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
'chon file template
duong_dan = Application.GetOpenFilename()
On Error Resume Next
Set template = Workbooks.Open(duong_dan)
For Each chi_nhanh In Sheet1.Range("A1:A" & lr)
template.SaveAs template.Path & "\" & chi_nhanh.Value & ".xlsx"
Next chi_nhanh
template.Close
Set chi_nhanh = Nothing
Set template = Nothing
Application.ScreenUpdating = True
End Sub