code ghi dữ liệu từ form vào cột K của sheet (1 người xem)

  • Thread starter Thread starter DMQ
  • Ngày gửi Ngày gửi
Liên hệ QC

Người dùng đang xem chủ đề này

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)
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
Đ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:
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
Thế mà code vẫn ghi vào cột A. Mong mọi người chỉ giáo!!!!!
 
Em có đoạn code này(Của một Thầy làm giúp)
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
Đ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:
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
Thế mà code vẫn ghi vào cột A. Mong mọi người chỉ giáo!!!!!
Hình như bạn bị nhầm rồi đó, chổ bạn nói là lấy dữ liệu thôi, còn chổ ghi dữ liệu hình như chổ này thì phải:
Mã:
            Sheet3.Cells(irow + N, 1) = CDate(ngay)   [COLOR=#ff0000]'Cột A[/COLOR]
            Sheet3.Cells(irow + N, 2) = UCase(sgd)    [COLOR=#FF0000]'Cột B[/COLOR]
            Sheet3.Cells(irow + N, 3) = UCase(sinv)   [COLOR=#FF0000]'Cột C[/COLOR]
Để chính xác bạn gửi file lên đây.
 
Upvote 0
Cám Ơn Bạn!!!!! Mình nhầm.+-+-+-+&&&%$R-=09=-=.,,!$@!!
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom