Closed Thread
Results 1 to 12 of 12

Need to format text in header, but value is generated using VBA

  1. #1
    Stacey
    Guest

    Need to format text in header, but value is generated using VBA

    Hello,

    I wanted to reference a cell value in my spreadsheet header and found out how to do that using this function:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)

    Dim WS As Worksheet
    For Each WS In Worksheets
    ActiveSheet.PageSetup.RightHeader = _
    Format(Worksheets("Time Period Info").Range("B3").Value)

    Next WS
    End Sub


    However, this leaves my text for this portion of the header at Arial Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set it to this format of text?

    Thanks for the help!

    --Stacey

  2. #2
    Andy Pope
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Hi,

    You can add formatting codes to change font size and bold.

    ActiveSheet.PageSetup.RightHeader = _
    "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)

    Where &B Turns bold printing on or off and &nn Prints the characters
    that follow in the specified font size. Use a two-digit number to
    specify a size in points.

    Use the Help and serach for 'Formatting Codes for Headers and Footers'
    for a comprehensive list.

    Cheers
    Andy

    Stacey wrote:
    > Hello,
    >
    > I wanted to reference a cell value in my spreadsheet header and found
    > out how to do that using this function:
    >
    > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >
    > Dim WS As Worksheet
    > For Each WS In Worksheets
    > ActiveSheet.PageSetup.RightHeader = _
    > Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Next WS
    > End Sub
    >
    >
    > However, this leaves my text for this portion of the header at Arial
    > Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    > set it to this format of text?
    >
    > Thanks for the help!
    >
    > --Stacey


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

  3. #3
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Exactly what I needed. Thanks again!
    "Andy Pope" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > You can add formatting codes to change font size and bold.
    >
    > ActiveSheet.PageSetup.RightHeader = _
    > "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Where &B Turns bold printing on or off and &nn Prints the characters that
    > follow in the specified font size. Use a two-digit number to specify a
    > size in points.
    >
    > Use the Help and serach for 'Formatting Codes for Headers and Footers' for
    > a comprehensive list.
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Hello,
    >> I wanted to reference a cell value in my spreadsheet header and found
    >> out how to do that using this function:
    >> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >> Dim WS As Worksheet
    >> For Each WS In Worksheets
    >> ActiveSheet.PageSetup.RightHeader = _
    >> Format(Worksheets("Time Period Info").Range("B3").Value)
    >> Next WS
    >> End Sub
    >> However, this leaves my text for this portion of the header at Arial
    >> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
    >> it to this format of text?
    >> Thanks for the help!
    >> --Stacey

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  4. #4
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    One more quick question:

    I want to keep the same type of text formatting, but I need it slightly
    revised so that it actually references two cells and displays them with a
    dash in the middle such as:
    Q1-Q2

    Is this possible? Currently I have it set to display just 1 cell looking
    like such:
    Q1

    Thanks for the help!

    I also need to to display the info for two different cells.
    "Andy Pope" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > You can add formatting codes to change font size and bold.
    >
    > ActiveSheet.PageSetup.RightHeader = _
    > "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Where &B Turns bold printing on or off and &nn Prints the characters that
    > follow in the specified font size. Use a two-digit number to specify a
    > size in points.
    >
    > Use the Help and serach for 'Formatting Codes for Headers and Footers' for
    > a comprehensive list.
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Hello,
    >> I wanted to reference a cell value in my spreadsheet header and found
    >> out how to do that using this function:
    >> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >> Dim WS As Worksheet
    >> For Each WS In Worksheets
    >> ActiveSheet.PageSetup.RightHeader = _
    >> Format(Worksheets("Time Period Info").Range("B3").Value)
    >> Next WS
    >> End Sub
    >> However, this leaves my text for this portion of the header at Arial
    >> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
    >> it to this format of text?
    >> Thanks for the help!
    >> --Stacey

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  5. #5
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    I found a work around. I created a new cell, combined the other two with a
    dash in the middle, and then referenced that cell instead. Thanks!
    "Andy Pope" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > You can add formatting codes to change font size and bold.
    >
    > ActiveSheet.PageSetup.RightHeader = _
    > "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Where &B Turns bold printing on or off and &nn Prints the characters that
    > follow in the specified font size. Use a two-digit number to specify a
    > size in points.
    >
    > Use the Help and serach for 'Formatting Codes for Headers and Footers' for
    > a comprehensive list.
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Hello,
    >> I wanted to reference a cell value in my spreadsheet header and found
    >> out how to do that using this function:
    >> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >> Dim WS As Worksheet
    >> For Each WS In Worksheets
    >> ActiveSheet.PageSetup.RightHeader = _
    >> Format(Worksheets("Time Period Info").Range("B3").Value)
    >> Next WS
    >> End Sub
    >> However, this leaves my text for this portion of the header at Arial
    >> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
    >> it to this format of text?
    >> Thanks for the help!
    >> --Stacey

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  6. #6
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Okay, last time, I promise. I often will select 4 different worksheets and
    have them all print at once, and I thought this VBA macro would update all
    of them (because they are all active sheets) at the same time. But for some
    reason its JUST updating the very first one with the header info. Do you
    know why and how I could fix it?

    Thanks again for the help!
    "Andy Pope" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi,
    >
    > You can add formatting codes to change font size and bold.
    >
    > ActiveSheet.PageSetup.RightHeader = _
    > "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Where &B Turns bold printing on or off and &nn Prints the characters that
    > follow in the specified font size. Use a two-digit number to specify a
    > size in points.
    >
    > Use the Help and serach for 'Formatting Codes for Headers and Footers' for
    > a comprehensive list.
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Hello,
    >> I wanted to reference a cell value in my spreadsheet header and found
    >> out how to do that using this function:
    >> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >> Dim WS As Worksheet
    >> For Each WS In Worksheets
    >> ActiveSheet.PageSetup.RightHeader = _
    >> Format(Worksheets("Time Period Info").Range("B3").Value)
    >> Next WS
    >> End Sub
    >> However, this leaves my text for this portion of the header at Arial
    >> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
    >> it to this format of text?
    >> Thanks for the help!
    >> --Stacey

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  7. #7
    Andy Pope
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Hi Stacey,

    Good to see you worked out the combined cell problem.

    Only one sheet is active even if you have multiple sheets selected.

    This revision to your code should process all sheets.

    Sub X()
    Dim WS As Worksheet

    For Each WS In Worksheets
    WS.PageSetup.RightHeader = _
    "&20&B" & _
    Format(Worksheets("Time Period Info").Range("B3").Value)
    Next WS
    End Sub

    Cheers
    Andy

    Stacey wrote:
    > Okay, last time, I promise. I often will select 4 different worksheets and
    > have them all print at once, and I thought this VBA macro would update all
    > of them (because they are all active sheets) at the same time. But for some
    > reason its JUST updating the very first one with the header info. Do you
    > know why and how I could fix it?
    >
    > Thanks again for the help!
    > "Andy Pope" <[email protected]> wrote in message
    > news:%[email protected]...
    >
    >>Hi,
    >>
    >>You can add formatting codes to change font size and bold.
    >>
    >>ActiveSheet.PageSetup.RightHeader = _
    >> "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>
    >>Where &B Turns bold printing on or off and &nn Prints the characters that
    >>follow in the specified font size. Use a two-digit number to specify a
    >>size in points.
    >>
    >>Use the Help and serach for 'Formatting Codes for Headers and Footers' for
    >>a comprehensive list.
    >>
    >>Cheers
    >>Andy
    >>
    >>Stacey wrote:
    >>
    >>>Hello,
    >>> I wanted to reference a cell value in my spreadsheet header and found
    >>>out how to do that using this function:
    >>> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>> Dim WS As Worksheet
    >>>For Each WS In Worksheets
    >>> ActiveSheet.PageSetup.RightHeader = _
    >>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>> Next WS
    >>>End Sub
    >>> However, this leaves my text for this portion of the header at Arial
    >>>Size 10 font Regular. I would like it Arial Size 20 Bold. How can I set
    >>>it to this format of text?
    >>> Thanks for the help!
    >>> --Stacey

    >>
    >>--
    >>
    >>Andy Pope, Microsoft MVP - Excel
    >>http://www.andypope.info

    >
    >
    >


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

  8. #8
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Thanks.
    I'm not sure I'm entering the information quite right. I left the portion
    at the top that read "BeforePrint" but it wouldn't work when I left it
    there. However, when I deleted it, the macro will no longer update. What
    do you suggest?
    "Andy Pope" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Stacey,
    >
    > Good to see you worked out the combined cell problem.
    >
    > Only one sheet is active even if you have multiple sheets selected.
    >
    > This revision to your code should process all sheets.
    >
    > Sub X()
    > Dim WS As Worksheet
    >
    > For Each WS In Worksheets
    > WS.PageSetup.RightHeader = _
    > "&20&B" & _
    > Format(Worksheets("Time Period Info").Range("B3").Value)
    > Next WS
    > End Sub
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Okay, last time, I promise. I often will select 4 different worksheets
    >> and have them all print at once, and I thought this VBA macro would
    >> update all of them (because they are all active sheets) at the same time.
    >> But for some reason its JUST updating the very first one with the header
    >> info. Do you know why and how I could fix it?
    >>
    >> Thanks again for the help!
    >> "Andy Pope" <[email protected]> wrote in message
    >> news:%[email protected]...
    >>
    >>>Hi,
    >>>
    >>>You can add formatting codes to change font size and bold.
    >>>
    >>>ActiveSheet.PageSetup.RightHeader = _
    >>> "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>
    >>>Where &B Turns bold printing on or off and &nn Prints the characters that
    >>>follow in the specified font size. Use a two-digit number to specify a
    >>>size in points.
    >>>
    >>>Use the Help and serach for 'Formatting Codes for Headers and Footers'
    >>>for a comprehensive list.
    >>>
    >>>Cheers
    >>>Andy
    >>>
    >>>Stacey wrote:
    >>>
    >>>>Hello,
    >>>> I wanted to reference a cell value in my spreadsheet header and found
    >>>> out how to do that using this function:
    >>>> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>>> Dim WS As Worksheet
    >>>>For Each WS In Worksheets
    >>>> ActiveSheet.PageSetup.RightHeader = _
    >>>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>> Next WS
    >>>>End Sub
    >>>> However, this leaves my text for this portion of the header at Arial
    >>>> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    >>>> set it to this format of text?
    >>>> Thanks for the help!
    >>>> --Stacey
    >>>
    >>>--
    >>>
    >>>Andy Pope, Microsoft MVP - Excel
    >>>http://www.andypope.info

    >>
    >>
    >>

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  9. #9
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Okay, so another quick revision. I found that I leave the portion that
    reads "Before Print" and eliminate the part of your code that reads Sub X().

    Now the problem I have is that when I select 4 of the worksheets and then
    hit Print or Print preview, it deselects the last 3 worksheets and only
    updates and prints the 1st one. Then after using the print utilitiy the 3
    additional worksheets are no longer highlighted and active. I'm not sure
    wha'ts causing this, but I need to be able to update and print all of the
    selected worksheets at once.
    "Andy Pope" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Stacey,
    >
    > Good to see you worked out the combined cell problem.
    >
    > Only one sheet is active even if you have multiple sheets selected.
    >
    > This revision to your code should process all sheets.
    >
    > Sub X()
    > Dim WS As Worksheet
    >
    > For Each WS In Worksheets
    > WS.PageSetup.RightHeader = _
    > "&20&B" & _
    > Format(Worksheets("Time Period Info").Range("B3").Value)
    > Next WS
    > End Sub
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Okay, last time, I promise. I often will select 4 different worksheets
    >> and have them all print at once, and I thought this VBA macro would
    >> update all of them (because they are all active sheets) at the same time.
    >> But for some reason its JUST updating the very first one with the header
    >> info. Do you know why and how I could fix it?
    >>
    >> Thanks again for the help!
    >> "Andy Pope" <[email protected]> wrote in message
    >> news:%[email protected]...
    >>
    >>>Hi,
    >>>
    >>>You can add formatting codes to change font size and bold.
    >>>
    >>>ActiveSheet.PageSetup.RightHeader = _
    >>> "&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>
    >>>Where &B Turns bold printing on or off and &nn Prints the characters that
    >>>follow in the specified font size. Use a two-digit number to specify a
    >>>size in points.
    >>>
    >>>Use the Help and serach for 'Formatting Codes for Headers and Footers'
    >>>for a comprehensive list.
    >>>
    >>>Cheers
    >>>Andy
    >>>
    >>>Stacey wrote:
    >>>
    >>>>Hello,
    >>>> I wanted to reference a cell value in my spreadsheet header and found
    >>>> out how to do that using this function:
    >>>> Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>>> Dim WS As Worksheet
    >>>>For Each WS In Worksheets
    >>>> ActiveSheet.PageSetup.RightHeader = _
    >>>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>> Next WS
    >>>>End Sub
    >>>> However, this leaves my text for this portion of the header at Arial
    >>>> Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    >>>> set it to this format of text?
    >>>> Thanks for the help!
    >>>> --Stacey
    >>>
    >>>--
    >>>
    >>>Andy Pope, Microsoft MVP - Excel
    >>>http://www.andypope.info

    >>
    >>
    >>

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  10. #10
    Andy Pope
    Guest

    Re: Need to format text in header, but value is generated using VBA

    This should do it just prior to printing.

    Private Sub Workbook_BeforePrint(Cancel As Boolean)

    Dim WS As Worksheet
    For Each WS In Worksheets
    WS.PageSetup.RightHeader = "&20&B" & _
    Format(Worksheets("Time Period Info").Range("B3").Value)

    Next WS
    End Sub

    Cheers
    Andy

    Stacey wrote:
    > Thanks.
    > I'm not sure I'm entering the information quite right. I left the portion
    > at the top that read "BeforePrint" but it wouldn't work when I left it
    > there. However, when I deleted it, the macro will no longer update. What
    > do you suggest?
    > "Andy Pope" <[email protected]> wrote in message
    > news:[email protected]...
    >
    >>Hi Stacey,
    >>
    >>Good to see you worked out the combined cell problem.
    >>
    >>Only one sheet is active even if you have multiple sheets selected.
    >>
    >>This revision to your code should process all sheets.
    >>
    >>Sub X()
    >> Dim WS As Worksheet
    >>
    >> For Each WS In Worksheets
    >> WS.PageSetup.RightHeader = _
    >> "&20&B" & _
    >>Format(Worksheets("Time Period Info").Range("B3").Value)
    >> Next WS
    >>End Sub
    >>
    >>Cheers
    >>Andy
    >>
    >>Stacey wrote:
    >>
    >>>Okay, last time, I promise. I often will select 4 different worksheets
    >>>and have them all print at once, and I thought this VBA macro would
    >>>update all of them (because they are all active sheets) at the same time.
    >>>But for some reason its JUST updating the very first one with the header
    >>>info. Do you know why and how I could fix it?
    >>>
    >>>Thanks again for the help!
    >>>"Andy Pope" <[email protected]> wrote in message
    >>>news:%[email protected]...
    >>>
    >>>
    >>>>Hi,
    >>>>
    >>>>You can add formatting codes to change font size and bold.
    >>>>
    >>>>ActiveSheet.PageSetup.RightHeader = _
    >>>>"&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>
    >>>>Where &B Turns bold printing on or off and &nn Prints the characters that
    >>>>follow in the specified font size. Use a two-digit number to specify a
    >>>>size in points.
    >>>>
    >>>>Use the Help and serach for 'Formatting Codes for Headers and Footers'
    >>>>for a comprehensive list.
    >>>>
    >>>>Cheers
    >>>>Andy
    >>>>
    >>>>Stacey wrote:
    >>>>
    >>>>
    >>>>>Hello,
    >>>>>I wanted to reference a cell value in my spreadsheet header and found
    >>>>>out how to do that using this function:
    >>>>>Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>>>>Dim WS As Worksheet
    >>>>>For Each WS In Worksheets
    >>>>> ActiveSheet.PageSetup.RightHeader = _
    >>>>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>> Next WS
    >>>>>End Sub
    >>>>>However, this leaves my text for this portion of the header at Arial
    >>>>>Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    >>>>>set it to this format of text?
    >>>>>Thanks for the help!
    >>>>>--Stacey
    >>>>
    >>>>--
    >>>>
    >>>>Andy Pope, Microsoft MVP - Excel
    >>>>http://www.andypope.info
    >>>
    >>>
    >>>

    >>--
    >>
    >>Andy Pope, Microsoft MVP - Excel
    >>http://www.andypope.info

    >
    >
    >


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

  11. #11
    Stacey
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Thanks. That did make it update prior to printing, but now I appear to have
    another problem.

    Now the problem I have is that when I select 4 of the worksheets and then
    hit Print or Print preview, it deselects the last 3 worksheets and only
    updates and prints the 1st one. Then after using the print utilitiy the 3
    additional worksheets are no longer highlighted and active. I'm not sure
    what's causing this, but I need to be able to update and print all of the
    selected worksheets at once.

    "Andy Pope" <[email protected]> wrote in message
    news:[email protected]...
    > This should do it just prior to printing.
    >
    > Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >
    > Dim WS As Worksheet
    > For Each WS In Worksheets
    > WS.PageSetup.RightHeader = "&20&B" & _
    > Format(Worksheets("Time Period Info").Range("B3").Value)
    >
    > Next WS
    > End Sub
    >
    > Cheers
    > Andy
    >
    > Stacey wrote:
    >> Thanks.
    >> I'm not sure I'm entering the information quite right. I left the
    >> portion at the top that read "BeforePrint" but it wouldn't work when I
    >> left it there. However, when I deleted it, the macro will no longer
    >> update. What do you suggest?
    >> "Andy Pope" <[email protected]> wrote in message
    >> news:[email protected]...
    >>
    >>>Hi Stacey,
    >>>
    >>>Good to see you worked out the combined cell problem.
    >>>
    >>>Only one sheet is active even if you have multiple sheets selected.
    >>>
    >>>This revision to your code should process all sheets.
    >>>
    >>>Sub X()
    >>> Dim WS As Worksheet
    >>>
    >>> For Each WS In Worksheets
    >>> WS.PageSetup.RightHeader = _
    >>> "&20&B" & _
    >>>Format(Worksheets("Time Period Info").Range("B3").Value)
    >>> Next WS
    >>>End Sub
    >>>
    >>>Cheers
    >>>Andy
    >>>
    >>>Stacey wrote:
    >>>
    >>>>Okay, last time, I promise. I often will select 4 different worksheets
    >>>>and have them all print at once, and I thought this VBA macro would
    >>>>update all of them (because they are all active sheets) at the same
    >>>>time. But for some reason its JUST updating the very first one with the
    >>>>header info. Do you know why and how I could fix it?
    >>>>
    >>>>Thanks again for the help!
    >>>>"Andy Pope" <[email protected]> wrote in message
    >>>>news:%[email protected]...
    >>>>
    >>>>
    >>>>>Hi,
    >>>>>
    >>>>>You can add formatting codes to change font size and bold.
    >>>>>
    >>>>>ActiveSheet.PageSetup.RightHeader = _
    >>>>>"&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>>
    >>>>>Where &B Turns bold printing on or off and &nn Prints the characters
    >>>>>that follow in the specified font size. Use a two-digit number to
    >>>>>specify a size in points.
    >>>>>
    >>>>>Use the Help and serach for 'Formatting Codes for Headers and Footers'
    >>>>>for a comprehensive list.
    >>>>>
    >>>>>Cheers
    >>>>>Andy
    >>>>>
    >>>>>Stacey wrote:
    >>>>>
    >>>>>
    >>>>>>Hello,
    >>>>>>I wanted to reference a cell value in my spreadsheet header and found
    >>>>>>out how to do that using this function:
    >>>>>>Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>>>>>Dim WS As Worksheet
    >>>>>>For Each WS In Worksheets
    >>>>>> ActiveSheet.PageSetup.RightHeader = _
    >>>>>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>>> Next WS
    >>>>>>End Sub
    >>>>>>However, this leaves my text for this portion of the header at Arial
    >>>>>>Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    >>>>>>set it to this format of text?
    >>>>>>Thanks for the help!
    >>>>>>--Stacey
    >>>>>
    >>>>>--
    >>>>>
    >>>>>Andy Pope, Microsoft MVP - Excel
    >>>>>http://www.andypope.info
    >>>>
    >>>>
    >>>>
    >>>--
    >>>
    >>>Andy Pope, Microsoft MVP - Excel
    >>>http://www.andypope.info

    >>
    >>
    >>

    >
    > --
    >
    > Andy Pope, Microsoft MVP - Excel
    > http://www.andypope.info




  12. #12
    Andy Pope
    Guest

    Re: Need to format text in header, but value is generated using VBA

    Hi Stacey,

    That latest code should not deselect any sheets.
    If you want you can email me, off newsgroup, your workbook and I will
    have a look see.

    Cheers
    Andy

    Stacey wrote:
    > Thanks. That did make it update prior to printing, but now I appear to have
    > another problem.
    >
    > Now the problem I have is that when I select 4 of the worksheets and then
    > hit Print or Print preview, it deselects the last 3 worksheets and only
    > updates and prints the 1st one. Then after using the print utilitiy the 3
    > additional worksheets are no longer highlighted and active. I'm not sure
    > what's causing this, but I need to be able to update and print all of the
    > selected worksheets at once.
    >
    > "Andy Pope" <[email protected]> wrote in message
    > news:[email protected]...
    >
    >>This should do it just prior to printing.
    >>
    >>Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>
    >> Dim WS As Worksheet
    >> For Each WS In Worksheets
    >> WS.PageSetup.RightHeader = "&20&B" & _
    >> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>
    >> Next WS
    >>End Sub
    >>
    >>Cheers
    >>Andy
    >>
    >>Stacey wrote:
    >>
    >>>Thanks.
    >>>I'm not sure I'm entering the information quite right. I left the
    >>>portion at the top that read "BeforePrint" but it wouldn't work when I
    >>>left it there. However, when I deleted it, the macro will no longer
    >>>update. What do you suggest?
    >>>"Andy Pope" <[email protected]> wrote in message
    >>>news:[email protected]...
    >>>
    >>>
    >>>>Hi Stacey,
    >>>>
    >>>>Good to see you worked out the combined cell problem.
    >>>>
    >>>>Only one sheet is active even if you have multiple sheets selected.
    >>>>
    >>>>This revision to your code should process all sheets.
    >>>>
    >>>>Sub X()
    >>>> Dim WS As Worksheet
    >>>>
    >>>> For Each WS In Worksheets
    >>>> WS.PageSetup.RightHeader = _
    >>>> "&20&B" & _
    >>>>Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>> Next WS
    >>>>End Sub
    >>>>
    >>>>Cheers
    >>>>Andy
    >>>>
    >>>>Stacey wrote:
    >>>>
    >>>>
    >>>>>Okay, last time, I promise. I often will select 4 different worksheets
    >>>>>and have them all print at once, and I thought this VBA macro would
    >>>>>update all of them (because they are all active sheets) at the same
    >>>>>time. But for some reason its JUST updating the very first one with the
    >>>>>header info. Do you know why and how I could fix it?
    >>>>>
    >>>>>Thanks again for the help!
    >>>>>"Andy Pope" <[email protected]> wrote in message
    >>>>>news:%[email protected]...
    >>>>>
    >>>>>
    >>>>>
    >>>>>>Hi,
    >>>>>>
    >>>>>>You can add formatting codes to change font size and bold.
    >>>>>>
    >>>>>>ActiveSheet.PageSetup.RightHeader = _
    >>>>>>"&20&B" & Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>>>
    >>>>>>Where &B Turns bold printing on or off and &nn Prints the characters
    >>>>>>that follow in the specified font size. Use a two-digit number to
    >>>>>>specify a size in points.
    >>>>>>
    >>>>>>Use the Help and serach for 'Formatting Codes for Headers and Footers'
    >>>>>>for a comprehensive list.
    >>>>>>
    >>>>>>Cheers
    >>>>>>Andy
    >>>>>>
    >>>>>>Stacey wrote:
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>>Hello,
    >>>>>>>I wanted to reference a cell value in my spreadsheet header and found
    >>>>>>>out how to do that using this function:
    >>>>>>>Private Sub Workbook_BeforePrint(Cancel As Boolean)
    >>>>>>>Dim WS As Worksheet
    >>>>>>>For Each WS In Worksheets
    >>>>>>> ActiveSheet.PageSetup.RightHeader = _
    >>>>>>> Format(Worksheets("Time Period Info").Range("B3").Value)
    >>>>>>> Next WS
    >>>>>>>End Sub
    >>>>>>>However, this leaves my text for this portion of the header at Arial
    >>>>>>>Size 10 font Regular. I would like it Arial Size 20 Bold. How can I
    >>>>>>>set it to this format of text?
    >>>>>>>Thanks for the help!
    >>>>>>>--Stacey
    >>>>>>
    >>>>>>--
    >>>>>>
    >>>>>>Andy Pope, Microsoft MVP - Excel
    >>>>>>http://www.andypope.info
    >>>>>
    >>>>>
    >>>>>
    >>>>--
    >>>>
    >>>>Andy Pope, Microsoft MVP - Excel
    >>>>http://www.andypope.info
    >>>
    >>>
    >>>

    >>--
    >>
    >>Andy Pope, Microsoft MVP - Excel
    >>http://www.andypope.info

    >
    >
    >


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1