bigbabol89
Thành viên thường trực
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
- Tham gia
- 15/10/12
- Bài viết
- 225
- Được thích
- 34
Option Explicit
Sub insertRowAndFillDownFomular()
Dim ws As Worksheet: Set ws = ThisWorkbook.ActiveSheet
Dim startDate As Date: startDate = ws.Range("C1").Value
Dim endDate As Date: endDate = ws.Range("D1").Value
Dim dateCounter As Date: dateCounter = startDate
Dim i As Long
Dim LR As Long
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
Dim dicMa As Object
Set dicMa = CreateObject("Scripting.Dictionary")
Dim xKey As Variant
For i = 4 To LR
xKey = ws.Range("A" & i).Value2
If Not dicMa.exists(xKey) Then
dicMa.Add xKey, ""
End If
Next i
i = 4
Dim k As Variant
For Each k In dicMa.Keys
Do
ws.Range("A" & i).Value2 = k
ws.Range("B" & i).Value = dateCounter
dateCounter = dateCounter + 1
i = i + 1
Loop Until dateCounter > endDate
dateCounter = startDate
Next k
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("C4", "D" & LR).FillDown
End Sub
Hì hì, lại là bạn giúp rồi.Bạn thử xem code này nhé. code mình viết ẩu lắm
Mã:Option Explicit Sub insertRowAndFillDownFomular() Dim ws As Worksheet: Set ws = ThisWorkbook.ActiveSheet Dim startDate As Date: startDate = ws.Range("C1").Value Dim endDate As Date: endDate = ws.Range("D1").Value Dim dateCounter As Date: dateCounter = startDate Dim i As Long Dim LR As Long LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row Dim dicMa As Object Set dicMa = CreateObject("Scripting.Dictionary") Dim xKey As Variant For i = 4 To LR xKey = ws.Range("A" & i).Value2 If Not dicMa.exists(xKey) Then dicMa.Add xKey, "" End If Next i i = 4 Dim k As Variant For Each k In dicMa.Keys Do ws.Range("A" & i).Value2 = k ws.Range("B" & i).Value = dateCounter dateCounter = dateCounter + 1 i = i + 1 Loop Until dateCounter > endDate dateCounter = startDate Next k LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row ws.Range("C4", "D" & LR).FillDown End Sub
Bạn ơi, xin lỗi bạn mình mới thử thì thấy :Không có chi. Bạn cứ đăng nhiều bài toán lên là mình vui rồi :v
Không đúng chỗ nào đó bạn? bạn gửi file chi tiết mô tả lỗi và kết quả mong muốn để mình xem thửBạn ơi, xin lỗi bạn mình mới thử thì thấy :
- Nếu cột Mã là định dạng TEXT thì code chạy không đúng.
- Nếu chỉ filldown các các ô chứa công thức thôi có được không nhỉ ?
Bạn xem giúp với nhé.
Cám ơn bạn
Không hiểu sao mình copy ra file mới thì lại chạy được rồi.Không đúng chỗ nào đó bạn? bạn gửi file chi tiết mô tả lỗi và kết quả mong muốn để mình xem thử