digita đã viết:Còn xóa các cột ẩn thì là:
[COLOR=darkblue]Sub[/COLOR] DelHiddenCols()
[COLOR=darkblue]Dim[/COLOR] r [COLOR=darkblue]As[/COLOR] Range, k [COLOR=darkblue]As[/COLOR] Range
[COLOR=darkblue]With[/COLOR] ActiveSheet
[COLOR=darkblue]Set[/COLOR] r = .Range(Cells(1, 1), Cells(1, .Cells.SpecialCells(xlCellTypeLastCell).Column))
[COLOR=darkblue]Set[/COLOR] k = r.SpecialCells(xlCellTypeVisible)
r.EntireColumn.Hidden = [COLOR=darkblue]False[/COLOR]
k.EntireColumn.Hidden = [COLOR=darkblue]True[/COLOR]
r.SpecialCells(xlCellTypeVisible).EntireColumn.Delete
r.EntireColumn.Hidden = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
Sub DelHiddenRows()
[color=darkblue]Sub[/color] DelHiddenCols()
[color=darkblue]Dim[/color] r [color=darkblue]As[/color] Range, k [color=darkblue]As[/color] Range
[color=darkblue]With[/color] ActiveSheet
[color=darkblue]Set[/color] r = .Range(Cells(1, 1), Cells(1, .Cells.SpecialCells(xlCellTypeLastCell).Column))
[color=darkblue]Set[/color] k = r.SpecialCells(xlCellTypeVisible)
[color=darkblue]If[/color] r.Cells.Count > k.Cells.Count [color=darkblue]Then[/color]
r.EntireColumn.Hidden = [color=darkblue]False[/color]
k.EntireColumn.Hidden = [color=darkblue]True[/color]
r.SpecialCells(xlCellTypeVisible).EntireColumn.Del ete
r.EntireColumn.Hidden = [color=darkblue]False[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]Set[/color] r = [color=darkblue]Nothing[/color]
[color=darkblue]Set[/color] k = [color=darkblue]Nothing[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
muigele đã viết:Tôi thấy mọi người hay nhắc đến VBA. Vậy VBA là gì? sử dụng như thế nào? Các bạn giải thích giúp tôi nhé
Thân!
Vấn đề không phải là dốt mà dốt mới là vấn đề!![]()
BNTT đã viết:Cái xóa hàng thì được còn cái xóa cột thì không bác Digita ơi (mặc dù đã sửa dùm bác chữ Delete rồi)
Sub DelHiddenRows()
Dim r As Range, k As Range
With ActiveSheet
Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Column)
[COLOR="Red"][B]Set k = r.SpecialCells(xlCellTypeVisible)[/B][/COLOR]
r.EntireColumn.Hidden = False
k.EntireColumn.Hidden = True
r.SpecialCells(xlCellTypeVisible).EntireColumn.Delete
r.EntireColumn.Hidden = False
End With
End Sub
Tunguyen đã viết:Em chạy thử nó báo lỗi này :
Run-time error '1004':
No cells were found.
rồi nó báo lỗi ở hàng này
Mã:Sub DelHiddenRows() Dim r As Range, k As Range With ActiveSheet Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Column) [COLOR="Red"][B]Set k = r.SpecialCells(xlCellTypeVisible)[/B][/COLOR] r.EntireColumn.Hidden = False k.EntireColumn.Hidden = True r.SpecialCells(xlCellTypeVisible).EntireColumn.Delete r.EntireColumn.Hidden = False End With End Sub
Sub DelHiddenRows()
Dim r As Range, k As Range
If Cells.Rows.Count - Cells.SpecialCells(xlCellTypeVisible).Count > 0 Then
With ActiveSheet
Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
Set k = r.SpecialCells(xlCellTypeVisible)
r.EntireRow.Hidden = False
k.EntireRow.Hidden = True
r.SpecialCells(xlCellTypeVisible).EntireRow.Delete
r.EntireRow.Hidden = False
End With
Set r = Nothing
Set k = Nothing
Else
MsgBox "Khong co hang an."
End If
End Sub
anhtuan1066 đã viết:Digita xem lại nha! Nếu vừa có hàng ẩn, vừa có cột ẩn thì code này sẽ báo sai, nó sẽ báo rằng "Không có hàng ẩn"... Vô lý!
Sub DelHiddenRows()
Dim r As Range, k As Range
If Cells.Rows.Count - Cells.SpecialCells(xlCellTypeVisible).Rows.Count > 0 Then
With ActiveSheet
Set r = .Range("A1:A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
Set k = r.SpecialCells(xlCellTypeVisible)
r.EntireRow.Hidden = False
k.EntireRow.Hidden = True
r.SpecialCells(xlCellTypeVisible).EntireRow.Delete
r.EntireRow.Hidden = False
End With
Set r = Nothing
Set k = Nothing
Else
MsgBox "Khong co hang de xoa."
End If
End Sub
Sub DelHiddenCols()
Dim r As Range, k As Range
If Cells.Columns.Count - Cells.SpecialCells(xlCellTypeVisible).Columns.Count > 0 Then
With ActiveSheet
Set r = .Range(Cells(1, 1), Cells(1, .Cells.SpecialCells(xlCellTypeLastCell).Column))
Set k = r.SpecialCells(xlCellTypeVisible)
If r.Cells.Count > k.Cells.Count Then
r.EntireColumn.Hidden = False
k.EntireColumn.Hidden = True
r.SpecialCells(xlCellTypeVisible).EntireColumn.Delete
r.EntireColumn.Hidden = False
End If
End With
Set r = Nothing
Set k = Nothing
Else
MsgBox "Khong co cot an de xoa."
End If
End Sub