tranthanh2200
Thành viên hoạt động
Em đang tập VBA mà viết song theo ý hiểu nhưng nó lỗi tùm lum. Nhờ các bác sửa giúp code này với a.
Mô tả: Em định tạo 1 file với tên là dulieu có 3 sheet data, cd, ccd
Sau đó past dữ liệu sau khi lọc từ file gốc sang.
Option Explicit
Sub taomoi()
Dim i As Byte
Dim Vungcd As Range
Dim Vungccd As Range
Dim wb As Workbook
Dim DC As Long
Dim DT As Range
Workbooks.Add
ActiveWorkbook.SaveAs "Dulieu.xlsm"
Set wb = Application.Workbooks("Dulieu")
For i = 1 To 2
Worksheets.Add
Next i
Sheet1.Name = "Data"
Sheet2.Name = "CD"
Sheet3.Name = "CCD"
Set Vungcd = Workbooks("Dulieu").Worksheets("CD").Range("A1")
Set Vungccd = Workbooks("Dulieu").Worksheets("CCD").Range("A1")
ThisWorkbooks.Worksheets("tudien").Select
Sheet2.Range("B2").Select
DC = ActiveWorkbook.Sheet2.Range("B" & Rows.Count).End(xlUp).Row
Set DT = Sheet2.Range("A2:E" & DC)
DT.AutoFilter Field:=5, Criteria1:=">=12", Operator:=xlAnd
DT.Copy
Vungcd.PasteSpecial xlPasteValues
DT.AutoFilter Field:=5, Criteria1:="<12", Operator:=xlAnd
DT.Copy
Vungccd.PasteSpecial xlPasteValues
DT.AutoFilter
DT.Copy
Application.Workbooks("Dulieu").Worksheets("Data").Range("A1").PasteSpecial xlPasteValues
End Sub
Mô tả: Em định tạo 1 file với tên là dulieu có 3 sheet data, cd, ccd
Sau đó past dữ liệu sau khi lọc từ file gốc sang.
Option Explicit
Sub taomoi()
Dim i As Byte
Dim Vungcd As Range
Dim Vungccd As Range
Dim wb As Workbook
Dim DC As Long
Dim DT As Range
Workbooks.Add
ActiveWorkbook.SaveAs "Dulieu.xlsm"
Set wb = Application.Workbooks("Dulieu")
For i = 1 To 2
Worksheets.Add
Next i
Sheet1.Name = "Data"
Sheet2.Name = "CD"
Sheet3.Name = "CCD"
Set Vungcd = Workbooks("Dulieu").Worksheets("CD").Range("A1")
Set Vungccd = Workbooks("Dulieu").Worksheets("CCD").Range("A1")
ThisWorkbooks.Worksheets("tudien").Select
Sheet2.Range("B2").Select
DC = ActiveWorkbook.Sheet2.Range("B" & Rows.Count).End(xlUp).Row
Set DT = Sheet2.Range("A2:E" & DC)
DT.AutoFilter Field:=5, Criteria1:=">=12", Operator:=xlAnd
DT.Copy
Vungcd.PasteSpecial xlPasteValues
DT.AutoFilter Field:=5, Criteria1:="<12", Operator:=xlAnd
DT.Copy
Vungccd.PasteSpecial xlPasteValues
DT.AutoFilter
DT.Copy
Application.Workbooks("Dulieu").Worksheets("Data").Range("A1").PasteSpecial xlPasteValues
End Sub