vuha
Thành viên hoạt động
- Tham gia
- 28/4/08
- Bài viết
- 159
- Được thích
- 34
[COLOR=#000000][COLOR=#0000bb][FONT=Courier New]Sub In_bang_CDPSTK_nam_click[/FONT][/COLOR][FONT=Courier New][COLOR=#007700]() [/COLOR][COLOR=#0000bb]Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B12:C12,F12,I12:V12"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B12"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireColumn[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"1:7"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb][SIZE=4][COLOR=red][B]True[/B][/COLOR][/SIZE] ActiveWorkbook[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Save Rows[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"8:9"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"K8"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A11"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlToRight[/COLOR][COLOR=#007700])).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlDown[/COLOR][COLOR=#007700])).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Selection[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]AutoFilter Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlToRight[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]AutoFilter Field[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#0000bb]27[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Criteria1[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#dd0000]"0"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Operator[/COLOR][COLOR=#007700]:=[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]xlAnd Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True ActiveWorkbook[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Save ActiveWindow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]SelectedSheets[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]PrintOut Copies[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]collate[/COLOR][COLOR=#007700]:=[/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]True End Sub [/FONT][/COLOR][/COLOR]
Tôi muốn unhide dòng 1 đến 7 cơ mà bạn, vậy thì chỗ đó phải là False mới đúng chứ? Nhưng không hiểu sao khi thực hiện lệnh vẫn hide dòng 7?Bạn sữa lại chỗ này thành True là được rồi.
Thân.Mã:[COLOR=#000000][COLOR=#0000bb][FONT=Courier New]Sub In_bang_CDPSTK_nam_click[/FONT][/COLOR][FONT=Courier New][COLOR=#007700]()[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B12:C12,F12,I12:V12"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"B12"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireColumn[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"1:7"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A1"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb][SIZE=4][COLOR=red][B]True[/B][/COLOR][/SIZE][/COLOR][/FONT] [COLOR=#0000bb][FONT=Courier New] ActiveWorkbook[/FONT][/COLOR][FONT=Courier New][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Save[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Rows[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"8:9"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"K8"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Activate[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"A11"[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlToRight[/COLOR][COLOR=#007700])).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Range[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlDown[/COLOR][COLOR=#007700])).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]AutoFilter[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]End[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]xlToRight[/COLOR][COLOR=#007700]).[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Select[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]AutoFilter Field[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#0000bb]27[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Criteria1[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#dd0000]"<>0"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]Operator[/COLOR][COLOR=#007700]:=[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]xlAnd[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] Selection[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EntireRow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Hidden [/COLOR][COLOR=#007700]= [/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]True[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] ActiveWorkbook[/COLOR][COLOR=#007700].[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Save[/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb] ActiveWindow[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]SelectedSheets[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]PrintOut Copies[/COLOR][COLOR=#007700]:=[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]collate[/COLOR][COLOR=#007700]:=[/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]True[/FONT][/COLOR] [FONT=Courier New][COLOR=#0000bb]End Sub [/COLOR][/FONT][/COLOR]
Code bạn viết dài và rườm rà quá! Mình sửa lại rồi đấyTôi muốn unhide dòng 1 đến 7, hide dòng 8; 9; 11 và lọc theo cột AA để in nhưng khi click button thì lại hide dòng 7, unhide dòng 8; 9. Tôi không biết nguyên nhân tại sao. Nhờ các bạn xem code và chỉnh sửa giùm. Thanks.
Sub In_bang_CDPSTK_nam_click()
On Error Resume Next
Range("B12:C12,F12,I12:V12").EntireColumn.Hidden = True
Range("1:7").EntireRow.Hidden = False
Rows("8:9").EntireRow.Hidden = True
Range("A11:AA" & [A65536].End(xlUp).Row).AutoFilter Field:=27, Criteria1:="<>0", Operator:=xlAnd
ActiveWindow.SelectedSheets.PrintOut Copies:=1, collate:=True
ActiveWorkbook.Save
End Sub
Sub In_bang_CDPSTK_nam_click()
Dim Rng As Range, sh As Worksheet
Application.ScreenUpdating = False
Set sh = ActiveSheet
sh.Columns.EntireColumn.Hidden = False
sh.AutoFilterMode = False
Range("B12:C12,F12,I12:V12").EntireColumn.Hidden = True
Range("1:7").EntireRow.Hidden = False
'ActiveWorkbook.Save'
Rows("8:9").EntireRow.Hidden = True
Set Rng = Range("AA11")
Set Rng = Range(Rng(1), Rng.End(xlDown))
Rng.AutoFilter field:=1, Criteria1:="<>0"
Rows("11:11").EntireRow.Hidden = True
'ActiveWorkbook.Save'
sh.PrintOut Copies:=1, collate:=True
sh.AutoFilterMode = False
Cells(1).Activate
Application.ScreenUpdating = True
End Sub