Hi dtaphuong,
For problem 1, change the code on sheet sub1 to:
(after updating Sub1 the Sub2 and Sub3 will have the same update)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
Sub1
Sheets("Sub2").Range("B1").Value = Target.Value
Sheets("Sub3").Range("B1").Value = Target.Value
End If
End Sub
For problem 2, change the code in module3 to:
(I do not fully understand the texts in the macro, but when I copy the update function for the B section to update F section, it seems to work)
Sub BonjourVn()
Dim DStong, TraCuu1, TraCuu2 As Variant, SoHD, Dmuc, Dulieu As Range, i As Long, j, k, m, n, o
' Xaìc lâòp thông tin chung
With Sheets("Total")
DStong = .[a1].CurrentRegion.Value
Set SoHD = .Range(.[a1], .[a1].End(4))
Set Dmuc = .Range(.[a1], .[a1].End(2))
End With
' Câòp nhâòt thông tin mõìi õÒ A
With Sheets("Sub3")
TraCuu1 = .[a4].CurrentRegion.Value
k = Application.Match(Sheet2.[b1], SoHD, 0)
End With
If TypeName(k) = "Error" Then
MsgBox "ko tim thay so HD nay"
Exit Sub
Else
Set Dulieu = Sheet1.[a1].Offset(k - 1).Resize(, UBound(DStong, 2))
For i = 1 To UBound(TraCuu1)
j = Application.Match(TraCuu1(i, 1), Dmuc, 0)
If TypeName(j) <> "Error" Then Dulieu.Cells(1, j) = TraCuu1(i, 2)
Next
With Sheets("Total")
.[a1].Offset(k - 1).Resize(, UBound(DStong, 2)).Value = Dulieu.Value
End With
MsgBox "Da cap nhat du lieu cho so HD " & Sheet2.[b1]
End If
'For F4:F11
With Sheets("Total")
DStong = .[a1].CurrentRegion.Value
Set SoHD = .Range(.[a1], .[a1].End(4))
Set Dmuc = .Range(.[a1], .[a1].End(2))
End With
' Câòp nhâòt thông tin mõìi õÒ A
With Sheets("Sub3")
TraCuu1 = .[f4].CurrentRegion.Value
k = Application.Match(Sheet2.[b1], SoHD, 0)
End With
If TypeName(k) = "Error" Then
MsgBox "ko tim thay so HD nay"
Exit Sub
Else
Set Dulieu = Sheet1.[f1].Offset(k - 1).Resize(, UBound(DStong, 2))
For i = 1 To UBound(TraCuu1)
j = Application.Match(TraCuu1(i, 1), Dmuc, 0)
If TypeName(j) <> "Error" Then Dulieu.Cells(1, j) = TraCuu1(i, 2)
Next
With Sheets("Total")
.[f1].Offset(k - 1).Resize(, UBound(DStong, 2)).Value = Dulieu.Value
End With
MsgBox "Da cap nhat du lieu cho so HD " & Sheet2.[b1]
End If
End Sub
Bookmarks