Dynamic print area based on date

Astrid123

New Member
Joined
Sep 25, 2017
Messages
16
Hello all,

In my Excel I have a range of dates. This calendar consists of quite some cells. What I want is to automatically set the print area based on today's date including the range of two days before and two days after and always print the first column.

For example if this is my sheet:

20-821-822-823-824-825-826-827-828-8
Applexxx
Pearx
Bananaxx
Orangex

<tbody>
</tbody>

I want to automatically print this (the current date +2 days before and after, and the first column)

22-823-824-825-826-8
Applex
Pearx
Bananax
Orangex

<tbody>
</tbody>

Does someone know how to do this?

Cheers!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello,

If you are using actual dates (and not Text ...) you should be able to use the Match function to locate your Today's date ... and resize your range accordingly ...

Say you would like when opening your file ... to get the cursor to jump directly to Today's date ...

Code:
Private Sub Workbook_Open()
' Macro to jump to Today's Date
Dim dateRng As Range
Dim DateCel As Range
Dim dateStr As String
  Worksheets("Sheet1").Select
  Set dateRng = Range("1:1")
    For Each DateCel In dateRng
        DateCel.Activate
        ActiveCell.Select
        On Error Resume Next
        dateStr = DateCel.Value
        If dateStr = Date Then
            DateCel.Select: Exit Sub
        End If
    Next DateCel
End Sub

Hope this will help
 
Last edited:
Upvote 0
Hello James,

Thank you for your answer, even though it's seems to be a very useful macro, it's not really what I've been looking for.

What I want the Excel to do is to automatically adjust the print area instead of jumping to today's date. I read that it is possible to do with the use of the name manager. But I don't know exactly how to manage this.

You have any suggestion?
 
Upvote 0
Hello,

Since I do not have your worksheet in front of me ...

Could you test the following formula : (as long as your dates are located in Row 2 ...)

Code:
=MATCH(TODAY(),2:2,0)

And let me know if you are getting a result ...
 
Upvote 0
As far as using the name manager ...

You could give a name to your range ... say myprint ...

and define it using the offset formula ... such as

Code:
=OFFSET(Sheet1!Z1,0,-2,8,5)

in this formula Sheet1!Z1 is he result of the previous Match formula ... needed to locate Today's date ...:wink:

HTH
 
Upvote 0
Re,

To expand on my previous message ...regarding your Advanced Dynamic Named Range ... :wink:

Code:
[TABLE="width: 28"]
<tbody>[TR]
[TD="class: xl63, width: 28"]=OFFSET(INDIRECT("Sheet1!"&ADDRESS(1,MATCH(TODAY(),Sheet1!$2:$2,0),4)),0,-2,8,5)[/TD]
[/TR]
</tbody>[/TABLE]

This formula is based on the following assumptions :

1. You are using Actual dates ... and not text ...
2. Your worksheet tab name is Sheet1
3. Your dates are located in row 2
4. You need to always have a 5 Column wide range
5. Your range has 8 rows

Let me know if you need further explanations ...

HTH
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top