snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub test()
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Data").UsedRange.Rows.Count
J = Worksheets("Cut of InterCo").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Cut of InterCo").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Data").Range("aC2:aC" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "Cut of InterCo" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Cut of InterCo").Range("A" & J + 1)
xRg(K).EntireRow.Delete
If CStr(xRg(K).Value) = "Cut of InterCo" Then
K = K - 1
End If
J = J + 1
End If
Next
Application.ScreenUpdating = True
Range("A2:AK20000").Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlNo
End Sub
You do not have the required permissions to view the files attached to this post.
Sub Test1()
Dim lr As Long, Rng As Range
lr = Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A1:AK" & lr).AutoFilter Field:=29, Criteria1:= _
"Cut of InterCo"
ActiveSheet.Range("A1:AK" & lr).AutoFilter Field:=23, Criteria1:="<>TT"
ActiveSheet.Range("A2:AK" & lr).Copy Sheets("Cut of InterCo").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Set Rng = Range("A2:A" & lr).SpecialCells(xlCellTypeVisible)
Rng.EntireRow.Delete
ActiveSheet.ShowAllData
End Sub