简体   繁体   中英

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.

The 2nd row always contains today's date. and then there is 2 years of data after that. 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.

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. 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.

Anyways if you want the row it can also be achieved via Excel Formula:

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

确定匹配数据行的公式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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