Consulting

Results 1 to 10 of 10

Thread: Solved: Max and Min dates in right header

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: Max and Min dates in right header

    I was wondering if it is possible to do a formula to put the min to max date in the right header from a column. I want it to look in my date column and then use the minimum date and maximum date to look like this (01\01\07-01\10\07). Is this possible?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =TEXT(MIN(A:A),"dd\\mm\\yy")&"-"&TEXT(MAX(A:A),"dd\\mm\\yy")

  3. #3
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    Quote Originally Posted by Djblois
    I was wondering if it is possible to do a formula to put the min to max date in the right header from a column. I want it to look in my date column and then use the minimum date and maximum date to look like this (01\01\07-01\10\07). Is this possible?
    are you referring to the header & footer??

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Yes - I want to put it in the right header

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Modifying Bob's formula, you could add the header by VBA prior to printing
    [VBA]Private Sub Workbook_BeforePrint(Cancel As Boolean)
    AddHeader
    End Sub

    Sub AddHeader()
    With Application.WorksheetFunction
    ActiveSheet.PageSetup.RightHeader = _
    .Text(.Min(Columns(1)), "dd\\mm\\yy") & "-" & .Text(.Max(Columns(1)), "dd\\mm\\yy")
    End With
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I just need help with one more thing the row with dates is on a seperate tab that I have set to detail

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub AddHeader()
    Dim ws As Worksheet
    Set ws = Sheets("detail")
    With Application.WorksheetFunction
    ActiveSheet.PageSetup.RightHeader = _
    .Text(.Min(ws.Columns(1)), "dd\\mm\\yy") & "-" & .Text(.Max(ws.Columns(1)), "dd\\mm\\yy")
    End With
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    That worked madmackillop but can I add formating to it?

    [VBA]ActiveSheet.PageSetup.RightHeader = .text(.Min(Columns(4)), "mm\\dd\\yy") & "-" & .text(.Max(Columns(4)), "mm\\dd\\yy")
    ActiveSheet.PageSetup.RightHeader = "&""Arial,Bold""&12"[/VBA]

    this doesn't work it just clears out the right header

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub AddHeader()
    Dim ws As Worksheet, HeadTxt As String
    Set ws = Sheets("detail")

    With Application.WorksheetFunction
    HeadTxt = .Text(.Min(ws.Columns(1)), "dd\\mm\\yy") & "-" & .Text(.Max(ws.Columns(1)), "dd\\mm\\yy")
    End With
    ActiveSheet.PageSetup.RightHeader = "&""Arial,Bold""&12 " & HeadTxt
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Thank you you are the best

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •