hoangld_vt
Thành viên mới
![](/diendan/data/PhoToDanhHieu/gold.gif)
- Tham gia
- 20/7/09
- Bài viết
- 4
- Được thích
- 0
Chào các bạn!
nhờ các bạn giúp mình đoạn code này nhé:
Mình muốn viết 1 đoạn chương trình để chuyển dữ liệu từ sheet nguồn sang sheet đích, với điều kiện là chỉ lấy dữ liệu ở sheet nguồn khi đã gặp đúng ngày hiện tại(today).
Tuy nhiên trong quá trình chạy thử đến đoạn chuyển dữ liệu sang sheet mới (trong file là chuển từ sheet "Thang 6" sang sheet "tinh toan") thì báo lỗi compiler: For without Next![000 :=\+ :=\+](/diendan/styles/smilies/a00.gif)
Đoạn mã cụ thể như sau(đến phần mình bôi đỏ là nó báo lỗi):
--------------------------------
Sub test()
Dim inputday, today As Date
Dim i, j, a, jtemp, itemp, hangdulieu, cotdulieu, hangdich As Integer
'=========================Kiem tra ngay co trung khong?
'thedate = Now
'thedate = format(Day(Now), "00") & format(Month(Now), "00") & Year(Now)
'Range("I1").Select
Sheets("Thang 6").Select
Range("A1").Select
Range("I1").NumberFormat = "dd/mm/yyyy"
today = Left(Now, 10)
ActiveCell.FormulaR1C1 = today
'====so sanh 2 ngay
'Range("AB4").NumberFormat = "dd/mm/yyyy"
inputday = Range("AB4").Value
If inputday = today Then
Range("k1").FormulaR1C1 = " trung "
Else
Range("k1").FormulaR1C1 = " k0trung "
End If
'Dim inputday, today As Date
'===========================duyet ngay va lay gia tri
Sheets("Thang 6").Select
Range("A1").Select
'a = 0
today = Left(Now, 10)
hangdich = 5
hangdulieu = 5
For j = 6 To 36 ' chay tung cot
i = 4
'itemp = i + 1
'jtemp = j
' hangdulieu = i + 1
' cotdulieu = j
inputday = Cells(i, j).Value ' kiem tra ngay thang trung hay khong?
While inputday = today
Exit For
Wend
'============================Chep du lieu sang sheet "tinhtoan"
For hangdulieu = 5 To 10
For hangdich = 5 To 10
Sheets("tinh toan").Cells(hangdich, 4) = ActiveSheet.Cells(hangdulieu, j)
Next hangdich
Next hangdulieu
Range("A1").Select
End Sub
nhờ các bạn giúp mình đoạn code này nhé:
Mình muốn viết 1 đoạn chương trình để chuyển dữ liệu từ sheet nguồn sang sheet đích, với điều kiện là chỉ lấy dữ liệu ở sheet nguồn khi đã gặp đúng ngày hiện tại(today).
Tuy nhiên trong quá trình chạy thử đến đoạn chuyển dữ liệu sang sheet mới (trong file là chuển từ sheet "Thang 6" sang sheet "tinh toan") thì báo lỗi compiler: For without Next
![000 :=\+ :=\+](/diendan/styles/smilies/a00.gif)
Đoạn mã cụ thể như sau(đến phần mình bôi đỏ là nó báo lỗi):
--------------------------------
Sub test()
Dim inputday, today As Date
Dim i, j, a, jtemp, itemp, hangdulieu, cotdulieu, hangdich As Integer
'=========================Kiem tra ngay co trung khong?
'thedate = Now
'thedate = format(Day(Now), "00") & format(Month(Now), "00") & Year(Now)
'Range("I1").Select
Sheets("Thang 6").Select
Range("A1").Select
Range("I1").NumberFormat = "dd/mm/yyyy"
today = Left(Now, 10)
ActiveCell.FormulaR1C1 = today
'====so sanh 2 ngay
'Range("AB4").NumberFormat = "dd/mm/yyyy"
inputday = Range("AB4").Value
If inputday = today Then
Range("k1").FormulaR1C1 = " trung "
Else
Range("k1").FormulaR1C1 = " k0trung "
End If
'Dim inputday, today As Date
'===========================duyet ngay va lay gia tri
Sheets("Thang 6").Select
Range("A1").Select
'a = 0
today = Left(Now, 10)
hangdich = 5
hangdulieu = 5
For j = 6 To 36 ' chay tung cot
i = 4
'itemp = i + 1
'jtemp = j
' hangdulieu = i + 1
' cotdulieu = j
inputday = Cells(i, j).Value ' kiem tra ngay thang trung hay khong?
While inputday = today
Exit For
Wend
'============================Chep du lieu sang sheet "tinhtoan"
For hangdulieu = 5 To 10
For hangdich = 5 To 10
Sheets("tinh toan").Cells(hangdich, 4) = ActiveSheet.Cells(hangdulieu, j)
Next hangdich
Next hangdulieu
Range("A1").Select
End Sub