Thầy cho e xin đoạn code set giá trị công thức về dạng value khi chạy vòng lặp xuất dữ liệu ra nhiều file với ạ
Chào bạn nếu trả dữ liệu ra dạng value như sau
sheet1.range("A1").value = sheet1.range("A1")
Thầy ơi e đưa công thức vào thì ở sheet mới tạo ra công thức đã được paste dạng value, nhưng nó báo lỗi không thể chạy sang biến i+1 tiếp theo, thầy xem giúp em đoạn code với ạ
Sub BangluongCX()
' xuat out
Dim i As Integer
'bo qua canh bao va nhap nhay khi chayj chuong trinh
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Gan gia tri dau tien
i = 7
'Quyet tung mcx
With ThisWorkbook.Sheets("CX_total")
While (.Cells(i, 3) <> "")
' gan MCX
ThisWorkbook.Sheets("BL").Cells(8, 8) = .Cells(i, 3)
'trich xuat shet BL ra file moi
ThisWorkbook.Sheets("BL").Copy
' Luu file sau khi trich xuat vao foder bang luong lai xe
Sheets("BL").Range("C14:C40").Value = Sheets("BL").Range("C14:C40").Value
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Bang luong chu xe\" & .Cells(5, 1) & " - " & .Cells(i, 3) & ".xlsx", Password:=.Cells(i, 42)
ActiveWorkbook.Close
i = i + 1
Wend
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Da hoan thanh"
End Sub
Chào bạn bạn có thể đính kèm file lên giúp gitiho nhé.
Em đã gửi file qua mail, nhờ thầy xem giúp em ạ.
Cảm ơn thầy nhiều
Chào bạn bạn gửi gmail lên google drive ở quyền chia sẻ rồi cho gitiho xin link nhé.
Chào bạn bạn có thể xem công thức xuất dữ liệu sau nhé
Sub ExportAsxlsx()
Dim MyFileName As String
Dim CurrentWB As Workbook, TempWB As Workbook
Set CurrentWB = ActiveWorkbook
ThisWorkbook.Sheets("BL").UsedRange.Copy
Set TempWB = Application.Workbooks.Add(1)
With TempWB.Sheets(1).Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
MyFileName = CurrentWB.Path & "\" & Left(CurrentWB.Name, Len(CurrentWB.Name) - 5) & ".xlsx"
Application.DisplayAlerts = False
TempWB.SaveAs Filename:=MyFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, Local:=True
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub
Phần MyfileName bạn có thể tuỳ chỉnh cho giống với name bạn cần xuất nhé.
Cảm ơn thầy em làm được rồi ạ
Chúc Duyên học tốt cảm ơn bạn đã tin tưởng và đồng hành