nhannv.banker
Thành viên mới
- Tham gia
- 7/1/10
- Bài viết
- 13
- Được thích
- 1
Chào các thành viên!
Mình có 1 sub nhờ các thành viên giúp đỡ, file của mình có 3 biến dòng cuối.
Mình cần copy (tự động dữ liệu thô từ sheet TF-Cha vào sheet "THEO DOI PHI BAO LANH"
Dữ liệu từ TF - cha được làm mới hàng ngày nên mình copy vào sheet "THEO DOI..."
Mình cần làm việc chỉ với vùng từ dòng cuối 1: trước khi thêm dữ liệu đến dòng cuối 3 (dòng cuối 2 bằng dòng cuối 1 + thêm 1) tức là vùng mới thêm trong ngày.
Các thành viên xem giúp em code sau khi chạy báo lỗi "Method 'Range' of object '_worksheet' fail"
Kính nhờ giúp đỡ !
Sub phi_baolanh()
Dim theodoiphi As Worksheet
Dim tfcha As Worksheet
Dim dcuoiphi1 As Long
Dim dcuoiphi2 As Long
Dim dcuoiphi3 As Long
Dim dongcuoitfcha As Long
Set theodoiphi = Worksheets("THEO DOI PHI BAO LANH")
Set tfcha = Worksheets("TF-CHA")
dcuoiphi1 = theodoiphi.Range("C" & Rows.Count).End(xlUp).Row
dongcuoitfcha = tfcha.Range("C" & Rows.Count).End(xlUp).Row
dcuoiphi2 = dcuoiphi1 + 1
dcuoiphi3 = dcuoiphi1 + dongcuoitfcha - 1
theodoiphi.Activate
With theodoiphi
.Range("G2") = .Range("C1").Value
.Range("H2") = .Range("C2").Value
End With
tfcha.Activate
tfcha.Range("C2:C" & dongcuoitfcha).Copy
theodoiphi.Range("C" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("H2:H" & dongcuoitfcha).Copy
theodoiphi.Range("D" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("A2:A" & dongcuoitfcha).Copy
theodoiphi.Range("E" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("F2:F" & dongcuoitfcha).Copy
theodoiphi.Range("A" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
With theodoiphi
.Range("B3").Copy
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).Copy
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).PasteSpecial xlPasteValues
.Range("F3").Copy
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).Copy
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).PasteSpecial xlPasteValues
.Range("G3").Copy
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).Copy
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).PasteSpecial xlPasteValues
.Range("H3").Copy
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).Copy
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).PasteSpecial xlPasteValues
Cells.Select
With Selection.Font
.Name = "Times New Roman"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
End With
Application.CutCopyMode = False
End Sub
Mình có 1 sub nhờ các thành viên giúp đỡ, file của mình có 3 biến dòng cuối.
Mình cần copy (tự động dữ liệu thô từ sheet TF-Cha vào sheet "THEO DOI PHI BAO LANH"
Dữ liệu từ TF - cha được làm mới hàng ngày nên mình copy vào sheet "THEO DOI..."
Mình cần làm việc chỉ với vùng từ dòng cuối 1: trước khi thêm dữ liệu đến dòng cuối 3 (dòng cuối 2 bằng dòng cuối 1 + thêm 1) tức là vùng mới thêm trong ngày.
Các thành viên xem giúp em code sau khi chạy báo lỗi "Method 'Range' of object '_worksheet' fail"
Kính nhờ giúp đỡ !
Sub phi_baolanh()
Dim theodoiphi As Worksheet
Dim tfcha As Worksheet
Dim dcuoiphi1 As Long
Dim dcuoiphi2 As Long
Dim dcuoiphi3 As Long
Dim dongcuoitfcha As Long
Set theodoiphi = Worksheets("THEO DOI PHI BAO LANH")
Set tfcha = Worksheets("TF-CHA")
dcuoiphi1 = theodoiphi.Range("C" & Rows.Count).End(xlUp).Row
dongcuoitfcha = tfcha.Range("C" & Rows.Count).End(xlUp).Row
dcuoiphi2 = dcuoiphi1 + 1
dcuoiphi3 = dcuoiphi1 + dongcuoitfcha - 1
theodoiphi.Activate
With theodoiphi
.Range("G2") = .Range("C1").Value
.Range("H2") = .Range("C2").Value
End With
tfcha.Activate
tfcha.Range("C2:C" & dongcuoitfcha).Copy
theodoiphi.Range("C" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("H2:H" & dongcuoitfcha).Copy
theodoiphi.Range("D" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("A2:A" & dongcuoitfcha).Copy
theodoiphi.Range("E" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
tfcha.Activate
tfcha.Range("F2:F" & dongcuoitfcha).Copy
theodoiphi.Range("A" & dcuoiphi1 + 1).PasteSpecial xlPasteValues
With theodoiphi
.Range("B3").Copy
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).Copy
.Range(Cells(dcuoiphi2, 2), Cells(dcuoiphi3, 2)).PasteSpecial xlPasteValues
.Range("F3").Copy
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).Copy
.Range(Cells(dcuoiphi2, 6), Cells(dcuoiphi3, 6)).PasteSpecial xlPasteValues
.Range("G3").Copy
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).Copy
.Range(Cells(dcuoiphi2, 7), Cells(dcuoiphi3, 7)).PasteSpecial xlPasteValues
.Range("H3").Copy
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).PasteSpecial xlPasteFormulas
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).Copy
.Range(Cells(dcuoiphi2, 8), Cells(dcuoiphi3, 8)).PasteSpecial xlPasteValues
Cells.Select
With Selection.Font
.Name = "Times New Roman"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
End With
Application.CutCopyMode = False
End Sub