简体   繁体   English

动态行打印区域excel VBA

[英]dynamic row print area excel VBA

I want to give the user the option to press " set print area " and the area printed is determined by which date they fill in. 我想为用户提供按“ set print area ”的选项,并且set print area取决于他们填写的日期。

The 2nd row always contains today's date. 第二行始终包含today's date. and then there is 2 years of data after that. 然后有2年的数据 Maybe the user only wants to print for first 3 months. 也许用户只想打印前三个月。

So the set print area code should be written something like. 因此,应将设置的打印区域代码写为类似内容。

row = len(date max - len today)

I am very new to VBA, so have no clue how to write this. 我是VBA的新手,所以不知道该怎么写。

thank you! 谢谢!

I'm not sure why you want to use VBA to do this when you can just use 'Filter' on the data you have. 我不确定为什么只对已拥有的数据使用“过滤器”时,为什么要使用VBA来执行此操作。 On the date column you can then use the in-built 'Date Filters' to filter out any range of data. 然后,您可以在日期列上使用内置的“日期过滤器”来过滤掉任何范围的数据。 Once you specify the filter, print command will only print the filtered data set and not the complete data set. 一旦指定了过滤器,print命令将仅打印过滤的数据集,而不打印完整的数据集。

Anyways if you want the row it can also be achieved via Excel Formula: 无论如何,如果您想要该行,也可以通过Excel公式实现:

=ADDRESS([dataset_first_row]+MATCH([set_print_area_date_cell],[dataset_date_range],-1)-1,2,4,1)

确定匹配数据行的公式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM