在excel中过滤后显示可见区域的宏

在excel中过滤后显示可见区域的宏

本文介绍了在excel中过滤后显示可见区域的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏,用于根据 A列值过滤表.现在,我想只在过滤器后打印 可见行,但可惜的是,它打印了所有行,包括在过滤器中隐藏的顶部和底部行.

I have a macro that filters the table based on column A values. Now I want to print only the visible rows after the filter, but sadly it prints all of the rows including the top and bottom rows that were hidden during the filter.

在我的工作表中,有 A:I 列中的数据,但打印区域只能是 C:I列-过滤后可见的行.

In my sheet, there are data from Column A:I, but the print area should only be Columns C:I - visible rows after filter.

以下是到目前为止我尝试过的无效代码:

Here are the codes that I've tried so far that didn't work:

代码1:

  ActiveSheet.PageSetup.printarea = Range("C3:I81000").Rows.SpecialCells(xlCellTypeVisible)

代码2:

 Dim lastrow As Long
 lastrow = ActiveSheet.UsedRange.Rows.Count
 Range(Cells(3, 3), Cells(lastrow, 9)).Select
 ActiveSheet.PageSetup.printarea = Selection.Address

还有其他建议吗?

推荐答案

最后,此代码成功了!:)谢谢大家!

Finally, this code worked! :) Thanks to all!

  ActiveSheet.PageSetup.PrintArea = Range("C3:I" & lastrow).Rows.SpecialCells(xlCellTypeVisible).Address

这篇关于在excel中过滤后显示可见区域的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:20