toandiennuoc123
Thành viên thường trực




- Tham gia
- 7/3/12
- Bài viết
- 239
- Được thích
- 9
Xin chào các ACE trên diễn đàn. Tôi có 2 đoạn code ghép lại với nhau cứ mỗi 1 lần chạy lại phải ấn Run macro , không biết tại sao nhờ các ACE giúp đỡ. Xin chân thành cám ơn.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim Tem As Variant
If Not Intersect(Target, [AF4:AO13]) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(29) = Target.Offset(29) + Tem
Target.ClearContents
Application.EnableEvents = True
ElseIf Not Intersect(Target, [AF20:AO29]) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(13, -12) = Target.Offset(13, -12) + Tem
Target.ClearContents
Application.EnableEvents = True
ElseIf Not Intersect(Range("AR20:AR29,AU20:AU29,AX20:AX29,BA19:BA30,BD19:BD30,BG16:BG30,BJ19:BJ22"), Target) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(, 1) = Target.Offset(, 1) + Tem
Target.ClearContents
Application.EnableEvents = True
End If
End Sub
Sub thaycongthuc()
Dim hangden, conlai
Dim arr1(), arr2(), arr3(), i, j
hangden = [BX20:CG29].Value
conlai = [ci20:cr29].Value
ReDim arr1(1 To 10, 1 To 10)
ReDim arr2(1 To 10, 1 To 10)
For i = 1 To 10
For j = 1 To 10
If hangden(i, j) > [bq18].Value Then
arr1(i, j) = [bq18].Value
Else
arr1(i, j) = hangden(i, j)
End If
If hangden(i, j) > arr1(i, j) Then
arr2(i, j) = hangden(i, j) - arr1(i, j)
End If
Next
Next
[bm20].Resize(10, 10) = arr1
[ci20].Resize(10, 10) = arr2
End Sub
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim Tem As Variant
If Not Intersect(Target, [AF4:AO13]) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(29) = Target.Offset(29) + Tem
Target.ClearContents
Application.EnableEvents = True
ElseIf Not Intersect(Target, [AF20:AO29]) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(13, -12) = Target.Offset(13, -12) + Tem
Target.ClearContents
Application.EnableEvents = True
ElseIf Not Intersect(Range("AR20:AR29,AU20:AU29,AX20:AX29,BA19:BA30,BD19:BD30,BG16:BG30,BJ19:BJ22"), Target) Is Nothing Then
Application.EnableEvents = False
Tem = Target
Target.Offset(, 1) = Target.Offset(, 1) + Tem
Target.ClearContents
Application.EnableEvents = True
End If
End Sub
Sub thaycongthuc()
Dim hangden, conlai
Dim arr1(), arr2(), arr3(), i, j
hangden = [BX20:CG29].Value
conlai = [ci20:cr29].Value
ReDim arr1(1 To 10, 1 To 10)
ReDim arr2(1 To 10, 1 To 10)
For i = 1 To 10
For j = 1 To 10
If hangden(i, j) > [bq18].Value Then
arr1(i, j) = [bq18].Value
Else
arr1(i, j) = hangden(i, j)
End If
If hangden(i, j) > arr1(i, j) Then
arr2(i, j) = hangden(i, j) - arr1(i, j)
End If
Next
Next
[bm20].Resize(10, 10) = arr1
[ci20].Resize(10, 10) = arr2
End Sub