vumian
Mỗi bậc thang là mỗi Cell
- Tham gia
- 12/3/07
- Bài viết
- 267
- Được thích
- 186
- Nghề nghiệp
- employee only, not a boss
Option Explicit: Option Base 1
Dim jJ As Long, Jw As Long, lRowA As Long, lRowB As Long
Sub GopDuLieu()
lRowA = Sheets("A").[b65432].End(xlUp).Row
lRowB = Sheets("B").[b65432].End(xlUp).Row
ReDim MgDL(lRowB - 2) As Boolean
With Sheets("A")
For jJ = 3 To lRowA
For Jw = 3 To lRowB
If .Cells(jJ, 2) = Sheets("B").Cells(Jw, 2) Then
.Cells(jJ, 3) = Sheets("B").Cells(Jw, 3)
MgDL(Jw - 2) = True: Exit For
End If
Next Jw, jJ
For Jw = 3 To lRowB
If Not MgDL(Jw - 2) Then
.Range("B" & .[b65432].End(xlUp).Row + 1) = Sheets("B").Cells(Jw, 2)
.Range("C" & .[b65432].End(xlUp).Row) = Sheets("B").Cells(Jw, 3)
End If
Next Jw
End With
End Sub
Bác ơi, Tuy là mang ý nghĩa gộp, nhưng nếu khi gộp thì dữ liệu chủ yếu dựa trên table 2,
Table mới sau khi gộp như ví dụ, thì hạng mục bbb,ccc,ddd không còn mới đúng
Đã đưa table mẫu sau khi gộp vào file, Bác xem giúp Bác xem lại giúp
Option Explicit: Option Base 1
Dim jJ As Long, Jw As Long, lRowA As Long, lRowB As Long, lRowG As Long
Sub GopDuLieu()
lRowA = Sheets("A").[b65432].End(xlUp).Row
lRowB = Sheets("B").[b65432].End(xlUp).Row
ReDim MgDL(lRowB - 2) As Boolean
With Sheets("Gop")
.Range("A2:K" & (lRowA + lRowB)).Clear
Sheets("A").[b2].Resize(1, 9).Copy Destination:=.[b2]
For jJ = 3 To lRowA
For Jw = 3 To lRowB
If Sheets("A").Cells(jJ, 2) = Sheets("B").Cells(Jw, 2) Then
lRowG = .[b65432].End(xlUp).Row + 1
Sheets("A").Cells(jJ, 2).Resize(1, 9).Copy _
Destination:=.Range("B" & lRowG)
.Range("C" & lRowG) = Sheets("B").Cells(Jw, 3)
MgDL(Jw - 2) = True: Exit For
End If
Next Jw, jJ
For Jw = 3 To lRowB
If Not MgDL(Jw - 2) Then
lRowG = .[b65432].End(xlUp).Row + 1
.Range("B" & lRowG) = Sheets("B").Cells(Jw, 2)
.Range("C" & lRowG) = Sheets("B").Cells(Jw, 3)
End If
Next Jw
End With
End Sub
Option Explicit: Option Base 1
Dim jJ As Long, Jw As Long, lRowA As Long, lRowB As Long
Sub GopDuLieu()
lRowA = Sheets("A").[b65432].End(xlUp).Row
lRowB = Sheets("B").[b65432].End(xlUp).Row
ReDim MangB(lRowB - 2) As Boolean: ReDim MangA(lRowA - 2) As Boolean '1'
Dim Rng As Range
With Sheets("A")
For jJ = 3 To lRowA
For Jw = 3 To lRowB
If .Cells(jJ, 2) = Sheets("B").Cells(Jw, 2) Then
.Cells(jJ, 3) = Sheets("B").Cells(Jw, 3): MangA(jJ - 2) = True '2'
MangB(Jw - 2) = True: Exit For
End If
Next Jw, jJ
'Thêm:'
For jJ = 3 To lRowA
If Not MangA(jJ - 2) Then
If Rng Is Nothing Then
Set Rng = .Cells(jJ, 1)
Else
Set Rng = Union(Rng, .Cells(jJ, 1))
End If: End If
Next jJ
Rng.EntireRow.Delete
'Hết thêm'
For Jw = 3 To lRowB
If Not MangB(Jw - 2) Then
.Range("B" & .[b65432].End(xlUp).Row + 1) = Sheets("B").Cells(Jw, 2)
.Range("C" & .[b65432].End(xlUp).Row) = Sheets("B").Cells(Jw, 3)
End If
Next Jw
End With
End Sub
Option Explicit
Dim ds6 As Long, ds7 As Long
Dim lRowS6 As Long, lRowS7 As Long
Sub ThemHangMuc()
lRowS6 = Sheet6.[B65432].End(xlUp).Row
lRowS7 = Sheet7.[B65432].End(xlUp).Row
With Sheet6 ' Sheet A'
For ds6 = 9 To lRowS6
For ds7 = 9 To lRowS7
If .Range("B" & ds6) = Sheet7.Range("B" & ds7) Then Exit For
Next ds7
If ds7 > lRowS7 And WorksheetFunction.Sum(.Range("I" & ds6 & ":S" & ds6)) > 0 Then
9 ' MsgBox ds7, , ds6''
.Range("B" & ds6 & ":S" & ds6).Copy _
Destination:=Sheet7.[B65432].End(xlUp).Offset(1, 0)
End If
Next ds6
End With
End Sub
Hai bác ơi, Em ccó 1 lỗi về giải thuật, hai bác mở file xem giúp
Cám ơn nhiều,
Option Explicit
Dim ds6 As Long, ds7 As Long
Dim lRowS6 As Long, lRowS7 As Long
Dim Timer_ As Double
Sub FindAndCopy()
Dim Rng As Range, Clls As Range
Timer_ = Timer
lRowS7 = Sheet7.[b65432].End(xlUp).Row
With Sheet6
For ds6 = 9 To .[b65432].End(xlUp).Row
Set Clls = Sheet7.Columns("B:B").Find(.Cells(ds6, 2), LookIn:=xlValues, _
LookAt:=xlWhole)
If Clls Is Nothing Then
If Rng Is Nothing Then
Set Rng = .Cells(ds6, 2).Resize(1, 18)
Else
Set Rng = Union(Rng, .Cells(ds6, 2).Resize(1, 18))
End If: End If
Next ds6
End With
If Not Rng Is Nothing Then _
Rng.Copy Destination:=Sheet7.Cells(lRowS7 + 1, 2)
MsgBox Timer - Timer_ 'Không quá .015625 gy nếu Sheet7 có 1.000 records dữ liệu'
End Sub
Sheet7.Range("B" & ds6 & ":S" & ds6).Font.ColorIndex = 5
Sub BayLoi()
On Error GoTo LoiCT
Dim VH As Integer
1 MsgBox "1"
2 MsgBox Str(4 / VH)
3 MsgBox "3"
Err_CT: Exit Sub
LoiCT:
Select Case Err
Case 13
Resume Next
Case Else
MsgBox Error$, , Erl: Resume Err_CT
End Select
End Sub
[B]Sub ThemHangMuc() [/B]
' . . . . . . . . . . . . . . '
'. . . . . . . . . . . . . . . '
9 [COLOR="LightBlue"]' MsgBox ds7, , ds6'[/COLOR]
[COLOR="DarkOrchid"] .Range("B" & ds6 & ":S" & ds6).Copy _
Destination:=Sheet7.[b65432].End(xlUp).Offset(1, 0)[/COLOR]
Sheet7.Range("B" & Sheet7.[b65432].End(xlUp).Row & ":S" & _
Sheet7.[b65432].End(xlUp).Row).Interior.ColorIndex = 5
[COLOR="darkorchid"] End If
Next ds6
End With[/COLOR]
[B]End Sub[/B]