Giúp sửa code xóa dòng hiện hành

Liên hệ QC

iloveit

Thành viên thường trực
Tham gia
2/3/13
Bài viết
212
Được thích
51
Giới tính
Nam
Nghề nghiệp
Tự do
Mình có đoạn code xóa dòng như sau, nhưng mình muốn sau khi copy hết công thức thì chọn lại cell ban đầu.
Cụ thể:
Khi mình đang ở cell A14 thì sau khi chạy sub sẽ chọn lại cell A14
Khi mình đang ở cell B15 thì sau khi chạy sub sẽ chọn lại cell B15

Nhờ mọi người giúp mình sửa đoạn code giúp! Chân thành cảm ơn.


Mã:
Sub xoadong()
With Sheet2
    ActiveCell.EntireRow.Delete
    Range("F12").Select
    Selection.AutoFill Destination:=Range("F12:F200"), Type:=xlFillDefault
    Range("J12").Select
    Selection.AutoFill Destination:=Range("J12:J200"), Type:=xlFillDefault
    Range("M12").Select
    Selection.AutoFill Destination:=Range("M12:M200"), Type:=xlFillDefault
    Range("P12").Select
    Selection.AutoFill Destination:=Range("P12:P200"), Type:=xlFillDefault
    Range("X12").Select
    Selection.AutoFill Destination:=Range("X12:X200"), Type:=xlFillDefault
    Range("Z12").Select
    Selection.AutoFill Destination:=Range("Z12:Z200"), Type:=xlFillDefault
End With
End Sub
 
Lần chỉnh sửa cuối:
Mình có đoạn code xóa dòng như sau, nhưng mình muốn sau khi copy hết công thức thì chọn lại cell ban đầu.
Cụ thể:
Khi mình đang ở cell A14 thì sau khi chạy sub sẽ chọn lại cell A14
Khi mình đang ở cell B15 thì sau khi chạy sub sẽ chọn lại cell B15

Nhờ mọi người giúp mình sửa đoạn code giúp! Chân thành cảm ơn.


Mã:
Sub xoadong()
With Sheet2
    ActiveCell.EntireRow.Delete
    Range("F12").Select
    Selection.AutoFill Destination:=Range("F12:F200"), Type:=xlFillDefault
    Range("J12").Select
    Selection.AutoFill Destination:=Range("J12:J200"), Type:=xlFillDefault
    Range("M12").Select
    Selection.AutoFill Destination:=Range("M12:M200"), Type:=xlFillDefault
    Range("P12").Select
    Selection.AutoFill Destination:=Range("P12:P200"), Type:=xlFillDefault
    Range("X12").Select
    Selection.AutoFill Destination:=Range("X12:X200"), Type:=xlFillDefault
    Range("Z12").Select
    Selection.AutoFill Destination:=Range("Z12:Z200"), Type:=xlFillDefault
    Range("A12").Select
End With
End Sub
Theo tôi chỉ cần thế này thôi
PHP:
Sub Xoadong()
    ActiveCell.EntireRow.Delete
    Range("A12:I12").AutoFill Destination:=Range("A12:I200"), Type:=xlFillDefault
End Sub
Xóa xong thì activecell vẫn là nó chứ có chạy đi đâu được đâu.
 
Upvote 0
Theo tôi chỉ cần thế này thôi
PHP:
Sub Xoadong()
    ActiveCell.EntireRow.Delete
    Range("A12:I12").AutoFill Destination:=Range("A12:I200"), Type:=xlFillDefault
End Sub
Xóa xong thì activecell vẫn là nó chứ có chạy đi đâu được đâu.


Đoạn code này nó copy luôn dữ liệu thô, trong khi mình chỉ muốn copy ở những cột có công thức
 
Upvote 0
Đoạn code này nó copy luôn dữ liệu thô, trong khi mình chỉ muốn copy ở những cột có công thức
Thế này có được không?
Mã:
Sub XoaDong()
    Dim Cll As Range
    On Error Resume Next
    ActiveCell.EntireRow.Delete
    For Each Cll In Sheet2.Range("F12:Z12").SpecialCells(xlCellTypeFormulas)
        Cll.AutoFill Destination:=Cll.Resize(189), Type:=xlFillDefault
    Next
End Sub
 
Upvote 0
Đoạn code này nó copy luôn dữ liệu thô, trong khi mình chỉ muốn copy ở những cột có công thức
Nhìn cái yêu cầu của sếp em chỉ nghĩ sếp muốn quay lại cell đầu sau khi xóa, chứ em đâu có biết là sếp cần copy ô có công thức!
 
Upvote 0
Khi mình đang ở cell A14 thì sau khi chạy sub sẽ chọn lại cell A14
Khi mình đang ở cell B15 thì sau khi chạy sub sẽ chọn lại cell B15
Để chọn lại cell ban đầu sau khi chạy sub thì tôi làm thế này
Mã:
Sub XoaDong()
Dim tmp
tmp = ActiveCell.Address

Code xóa dòng của bạn

Range(tmp).select
End sub
 
Upvote 0
Upvote 0
Thế này có được không?
Mã:
Sub XoaDong()
    Dim Cll As Range
    On Error Resume Next
    ActiveCell.EntireRow.Delete
    For Each Cll In Sheet2.Range("F12:Z12").SpecialCells(xlCellTypeFormulas)
        Cll.AutoFill Destination:=Cll.Resize(189), Type:=xlFillDefault
    Next
End Sub

Code này chạy rất tốt. Cám ơn anh!
 
Upvote 0
Để chọn lại cell ban đầu sau khi chạy sub thì tôi làm thế này
Mã:
Sub XoaDong()
Dim tmp
tmp = ActiveCell.Address

Code xóa dòng của bạn

Range(tmp).select
End sub

Cám ơn bạn. Nhờ bạn mình học thêm được 1 cách nữa
 
Upvote 0
Web KT
Back
Top Bottom