Xin giúp đỡ code vba để cập nhập dữ liệu bảng tính (1 người xem)

Liên hệ QC

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

tuandat106

Thành viên mới
Tham gia
19/4/11
Bài viết
49
Được thích
2
Mình có bảng dữ liêu tại sheet1, ở sheet2 mình chọn theo stt để xem dữ liệu ở bảng sheet1. tuy nhiên có những trường còn thiếu. vậy nhờ ace GPE code vba nút lệnh cập nhập dữ liệu vào bảng tính tương đương với số stt mình chọn.
Mình có ghi chú chi tiết ở file đính kèm.
Mong anh chị giúp đỡ
thanks.
 

File đính kèm

Mình có bảng dữ liêu tại sheet1, ở sheet2 mình chọn theo stt để xem dữ liệu ở bảng sheet1. tuy nhiên có những trường còn thiếu. vậy nhờ ace GPE code vba nút lệnh cập nhập dữ liệu vào bảng tính tương đương với số stt mình chọn.
Mình có ghi chú chi tiết ở file đính kèm.
Mong anh chị giúp đỡ
thanks.

Bạn dùng thử code sau. --=0

Mã:
'Option Explicit

Sub timvathaythe()
Dim Gtri, KQtim As Range
Gtri = Sheets("Sheet2").Range("B21")
Set KQtim = Sheets("Sheet1").Range("A:A").Find(Gtri)
    
    If Not KQtim Is Nothing Then
        With Sheets("Sheet1")
            .Range(KQtim.Address).Offset(0, 1).Value = Range("B22").Value
            .Range(KQtim.Address).Offset(0, 2).Value = Range("B23").Value
            .Range(KQtim.Address).Offset(0, 3).Value = Range("B24").Value
            .Range(KQtim.Address).Offset(0, 4).Value = Range("B25").Value
            .Range(KQtim.Address).Offset(0, 5).Value = Range("B26").Value
            .Range(KQtim.Address).Offset(0, 6).Value = Range("B27").Value
        End With
    End If
End Sub

Đưa nó vào nút Cập nhật tại "Sheet2".
 
Upvote 0
thanks bạn, rất nhanh và rất đúng ý
Bạn dùng thử code sau. --=0

Mã:
'Option Explicit

Sub timvathaythe()
Dim Gtri, KQtim As Range
Gtri = Sheets("Sheet2").Range("B21")
Set KQtim = Sheets("Sheet1").Range("A:A").Find(Gtri)
    
    If Not KQtim Is Nothing Then
        With Sheets("Sheet1")
            .Range(KQtim.Address).Offset(0, 1).Value = Range("B22").Value
            .Range(KQtim.Address).Offset(0, 2).Value = Range("B23").Value
            .Range(KQtim.Address).Offset(0, 3).Value = Range("B24").Value
            .Range(KQtim.Address).Offset(0, 4).Value = Range("B25").Value
            .Range(KQtim.Address).Offset(0, 5).Value = Range("B26").Value
            .Range(KQtim.Address).Offset(0, 6).Value = Range("B27").Value
        End With
    End If
End Sub

Đưa nó vào nút Cập nhật tại "Sheet2".
 
Upvote 0
Bạn dùng thử code sau. --=0

Mã:
'Option Explicit

Sub timvathaythe()
Dim Gtri, KQtim As Range
Gtri = Sheets("Sheet2").Range("B21")
Set KQtim = Sheets("Sheet1").Range("A:A").Find(Gtri)
    
    If Not KQtim Is Nothing Then
        With Sheets("Sheet1")
            .Range(KQtim.Address).Offset(0, 1).Value = Range("B22").Value
            .Range(KQtim.Address).Offset(0, 2).Value = Range("B23").Value
            .Range(KQtim.Address).Offset(0, 3).Value = Range("B24").Value
            .Range(KQtim.Address).Offset(0, 4).Value = Range("B25").Value
            .Range(KQtim.Address).Offset(0, 5).Value = Range("B26").Value
            .Range(KQtim.Address).Offset(0, 6).Value = Range("B27").Value
        End With
    End If
End Sub

Đưa nó vào nút Cập nhật tại "Sheet2".
Copy- Paste Values nó 1 phát được không nhỉ?
PHP:
Sub timvathaythe()
Dim STT As Long, KQtim As Range
STT = Sheets("Sheet2").Range("B21").Value
Set KQtim = Sheets("Sheet1").Range("A1:A100").Find(STT)
    If Not KQtim Is Nothing Then
        Sheet2.Range("B22:B27").Copy
        KQtim.Offset(, 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
        Application.CutCopyMode = False
    End If
End Sub
 
Upvote 0

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

Back
Top Bottom