DMQ
Thành viên dốt
- Tham gia
- 21/3/12
- Bài viết
- 722
- Được thích
- 57
- Giới tính
- Nam
Em có đoạn code này(Của một Thầy làm giúp)
Đoạn code trên ghi dữ liệu vào cột A của Sheet3, bây giờ em tạo một Form giống y chang, và muốn ghi vào cột K của Sheet3 và em sửa A thành K:
Thế mà code vẫn ghi vào cột A. Mong mọi người chỉ giáo!!!!!
Mã:
Private Sub ghi_Click()
Dim i As Integer, N As Long
ngay = Trim(ngay)
sgd = Trim(sgd)
If ngay = "" Or sgd = "" Or Not IsNumeric(tsl) Then MsgBox ("Ban chua nhap ngay hoac so giam dinh hoac tong san luong sai"), vbExclamation: Exit Sub
ngay.SetFocus
If ListBox1.ListCount = 0 Then MsgBox ("ban chua cap nhat Noi dung vao Listbox"), vbExclamation: Exit Sub
Application.ScreenUpdating = False
irow = Sheet3.Cells(Rows.Count, [B][COLOR=#ff0000]"A"[/COLOR][/B]).End(xlUp).Offset(1, 0).Row
For i = 0 To ListBox1.ListCount - 1
Sheet3.Cells(irow + N, 1) = CDate(ngay)
Sheet3.Cells(irow + N, 2) = UCase(sgd)
Sheet3.Cells(irow + N, 3) = UCase(sinv)
With ListBox1
If Left(.List(i, 1), 1) = "0" Then
Sheet3.Cells(irow + N, 4) = "'" & .List(i, 1)
Else
Sheet3.Cells(irow + N, 4) = UCase(.List(i, 1))
End If
Sheet3.Cells(irow + N, 5) = .List(i, 2) 'kich co
Sheet3.Cells(irow + N, 6) = CDbl(Format(.List(i, 3), "#,##0"))
End With
N = N + 1
Next
ngay = ""
sgd = ""
sinv = ""
tb_MDK = ""
dvt = ""
sl = ""
ListBox1.Clear
Application.ScreenUpdating = True
MsgBox ("cap nhat xong")
ngay.SetFocus
End Sub
Mã:
Private Sub ghi_Click(
)Dim i As Integer, N As Long
ngay = Trim(ngay)
sgd = Trim(sgd)
If ngay = "" Or sgd = "" Or Not IsNumeric(tsl) Then MsgBox ("Ban chua nhap ngay hoac so giam dinh hoac tong san luong sai"), vbExclamation: Exit Sub
ngay.SetFocus
If ListBox1.ListCount = 0 Then MsgBox ("ban chua cap nhat Noi dung vao Listbox"), vbExclamation: Exit Sub
Application.ScreenUpdating = False
irow = Sheet3.Cells(Rows.Count,[B][COLOR=#ff0000] "K"[/COLOR][/B]).End(xlUp).Offset(1, 0).Row [B][COLOR=#ff0000]<- sửa A thành K[/COLOR][/B]
For i = 0 To ListBox1.ListCount - 1
Sheet3.Cells(irow + N, 1) = CDate(ngay)
Sheet3.Cells(irow + N, 2) = UCase(sgd)
Sheet3.Cells(irow + N, 3) = UCase(sinv)
With ListBox1
If Left(.List(i, 1), 1) = "0" Then
Sheet3.Cells(irow + N, 4) = "'" & .List(i, 1)
Else
Sheet3.Cells(irow + N, 4) = UCase(.List(i, 1))
End If
Sheet3.Cells(irow + N, 5) = .List(i, 2) 'kich co
Sheet3.Cells(irow + N, 6) = CDbl(Format(.List(i, 3), "#,##0"))
End With
N = N + 1
Next
ngay = ""
sgd = ""
sinv = ""
tb_MDK = ""
dvt = ""
sl = ""
ListBox1.Clear
Application.ScreenUpdating = True
MsgBox ("cap nhat xong")
ngay.SetFocus
End Sub