Code update du liệu

Liên hệ QC

nguyenvietviet

Thành viên hoạt động
Tham gia
4/3/08
Bài viết
110
Được thích
11
Nghề nghiệp
Nhân viên văn phòng
Mọi người sửa giúp em đoạn code này với.
Em có file tự động update update khi thêm dữ liệu mới vào cột B thì nó sẽ update vào cột G, nhưng em mới vó cập nhập sang cột B của sheet 2 mong mọi người giúp.
 

File đính kèm

  • Tu dong cap ok.xls
    27.5 KB · Đọc: 48
Mọi người sửa giúp em đoạn code này với.
Em có file tự động update update khi thêm dữ liệu mới vào cột B thì nó sẽ update vào cột G, nhưng em mới vó cập nhập sang cột B của sheet 2 mong mọi người giúp.
Right Click vào sheet2 ==> View Code ==> chép code này vào
Mã:
Private Sub Worksheet_Activate()
Dim Vung, d, Cll
    Vung = Sheets("sheet1").Range(Sheets("sheet1").[B2], Sheets("sheet1").[B20000].End(xlUp))
    Set d = CreateObject("scripting.dictionary")
        For Each Cll In Vung
            If Cll <> "" Then
                If Not d.exists(Cll) Then d.Add Cll, ""
            End If
        Next Cll
    [B2:B10000].ClearContents
    [B2].Resize(d.Count) = Application.WorksheetFunction.Transpose(d.keys)
    Range([B2], [B20000].End(xlUp)).Sort Key1:=Range("B1"), Order1:=xlAscending
End Sub
Thân
 
Upvote 0
Nếu không dùng dao to búa lớn như bác Concogia thì dùng code như của bạn, chỉnh lại chút thôi:

PHP:
Private Sub WorkSheet_Change(ByVal target As Range)
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Not Intersect(target, Range("B2:B1000")) Is Nothing Then
        Sheet2.Range("B:B").ClearContents
        Range([B1], [B65536].End(xlUp)).AdvancedFilter _
        Action:=xlFilterCopy, CopyToRange:=Sheet2.[B1], Unique:=True
        Range(Sheet2.[B1], Sheet2.[B65536].End(xlUp)).Sort Sheet2.[B1], 1, , , , , , xlYes
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0
người ta muốn cập nhật vào cột B của sheet 2 cơ mà (qua sheet khác)
 
Upvote 0
Web KT
Back
Top Bottom