Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
SueJB
 
Posts: n/a
Default Displaying formulae changes formatting

Hi all,

Can anyone help with a strange quirk? I have a spreadsheet with a series of
numbers which have to be formatted to 1 decimal place. These show fine in
"normal" mode.

If I display formulae, some of the cells not containing formulae lose their
formatting - numbers with a decimal part are still shown to one place (eg
1.6) but those without lose the decimal (eg 1 not 1.0). All attempts to
change the formatting fail.

I need to be able to print the spreadsheet with formulae but also with
values displayed to one d.p. and I'm currently beaten.

Can anyone advise?

Thanks
SueJB
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
macropod
 
Posts: n/a
Default Displaying formulae changes formatting

Hi Sue,

The following macro adds the formulae to the comments for each selected
cell, or even the whole worksheet, and displays the comments in an
appropriately-sized comment box. This should allow you to both display the
formulae and their results. Depending on what you're trying to achieve, and
how crowded your worksheet is, you may still need to do a bit of
reformatting, and maybe get the macro the position the comments differently,
but showing/hiding the formulae will then be as easy as toggling the comment
display on/off.

Sub AddFormulaToComment()
Dim CommentRange As Range, TargetCell As Range
'skip over errors caused by trying to delete comments in cells with no
comments
On Error Resume Next
'If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
'If the cell contains a formula, make it a comment.
For Each TargetCell In CommentRange
With TargetCell
'check whether the cell has a formula
If Left(.Formula, 1) = "=" Then
'delete any existing comment
.Comment.Delete
'add a new comment
.AddComment
'copy the formula into the comment box
.Comment.Text Text:=.Formula
'display the comment
.Comment.Visible = True
With .Comment.Shape
'automatically resizes the comment
.TextFrame.AutoSize = True
'position the comment adjacent to its cell
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25
End With
End If
End With
Next
MsgBox " To print the comments, choose" & vbCrLf & _
" File|Page Setup|Sheet|Comments," & vbCrLf & _
"then choose the required print option.", vbOKOnly
End Sub

Cheers


"SueJB" wrote in message
...
Hi all,

Can anyone help with a strange quirk? I have a spreadsheet with a series

of
numbers which have to be formatted to 1 decimal place. These show fine in
"normal" mode.

If I display formulae, some of the cells not containing formulae lose

their
formatting - numbers with a decimal part are still shown to one place (eg
1.6) but those without lose the decimal (eg 1 not 1.0). All attempts to
change the formatting fail.

I need to be able to print the spreadsheet with formulae but also with
values displayed to one d.p. and I'm currently beaten.

Can anyone advise?

Thanks
SueJB



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
SueJB
 
Posts: n/a
Default Displaying formulae changes formatting

Hi macropod

Many thanks for replying. This is certainly an interesting way of resolving
the problem, but unfortunately the spreadsheet must be printed with the
formulae in the relevant cells and the values in the non-formula cells
showing to one decimal place.

Thanks for your suggestion, though, much appreciated.

SueJB

"macropod" wrote:

Hi Sue,

The following macro adds the formulae to the comments for each selected
cell, or even the whole worksheet, and displays the comments in an
appropriately-sized comment box. This should allow you to both display the
formulae and their results. Depending on what you're trying to achieve, and
how crowded your worksheet is, you may still need to do a bit of
reformatting, and maybe get the macro the position the comments differently,
but showing/hiding the formulae will then be as easy as toggling the comment
display on/off.

Sub AddFormulaToComment()
Dim CommentRange As Range, TargetCell As Range
'skip over errors caused by trying to delete comments in cells with no
comments
On Error Resume Next
'If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
'If the cell contains a formula, make it a comment.
For Each TargetCell In CommentRange
With TargetCell
'check whether the cell has a formula
If Left(.Formula, 1) = "=" Then
'delete any existing comment
.Comment.Delete
'add a new comment
.AddComment
'copy the formula into the comment box
.Comment.Text Text:=.Formula
'display the comment
.Comment.Visible = True
With .Comment.Shape
'automatically resizes the comment
.TextFrame.AutoSize = True
'position the comment adjacent to its cell
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25
End With
End If
End With
Next
MsgBox " To print the comments, choose" & vbCrLf & _
" File|Page Setup|Sheet|Comments," & vbCrLf & _
"then choose the required print option.", vbOKOnly
End Sub

Cheers


"SueJB" wrote in message
...
Hi all,

Can anyone help with a strange quirk? I have a spreadsheet with a series

of
numbers which have to be formatted to 1 decimal place. These show fine in
"normal" mode.

If I display formulae, some of the cells not containing formulae lose

their
formatting - numbers with a decimal part are still shown to one place (eg
1.6) but those without lose the decimal (eg 1 not 1.0). All attempts to
change the formatting fail.

I need to be able to print the spreadsheet with formulae but also with
values displayed to one d.p. and I'm currently beaten.

Can anyone advise?

Thanks
SueJB




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
macropod
 
Posts: n/a
Default Displaying formulae changes formatting

Hi Sue,

When Excel's displaying formulae, it can't display both the formula and
result for a given cell (at least with Excel 2000 and earlier). Any cells
with values are simply displayed as per the raw data (eg dates get converted
to numbers, decimal values get truncated at the last non-zero value, etc.).

With the macro I posted, you can display both the formula and it's result,
without compromising any of the value formatting. If you want to have both
the formula and its result appear in the same cell, you could increase the
row height, and re-position the comment in code to put it within the cell
and above/below the value, or you could increase the column width and put
the formula beside the result. If you don't want the formula's result to
show, re-position the comment in code to put it over the result.
repositioning the comment is managed by changing the values in the lines:
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25

Cheers


"SueJB" wrote in message
...
Hi macropod

Many thanks for replying. This is certainly an interesting way of

resolving
the problem, but unfortunately the spreadsheet must be printed with the
formulae in the relevant cells and the values in the non-formula cells
showing to one decimal place.

Thanks for your suggestion, though, much appreciated.

SueJB

"macropod" wrote:

Hi Sue,

The following macro adds the formulae to the comments for each selected
cell, or even the whole worksheet, and displays the comments in an
appropriately-sized comment box. This should allow you to both display

the
formulae and their results. Depending on what you're trying to achieve,

and
how crowded your worksheet is, you may still need to do a bit of
reformatting, and maybe get the macro the position the comments

differently,
but showing/hiding the formulae will then be as easy as toggling the

comment
display on/off.

Sub AddFormulaToComment()
Dim CommentRange As Range, TargetCell As Range
'skip over errors caused by trying to delete comments in cells with no
comments
On Error Resume Next
'If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
'If the cell contains a formula, make it a comment.
For Each TargetCell In CommentRange
With TargetCell
'check whether the cell has a formula
If Left(.Formula, 1) = "=" Then
'delete any existing comment
.Comment.Delete
'add a new comment
.AddComment
'copy the formula into the comment box
.Comment.Text Text:=.Formula
'display the comment
.Comment.Visible = True
With .Comment.Shape
'automatically resizes the comment
.TextFrame.AutoSize = True
'position the comment adjacent to its cell
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25
End With
End If
End With
Next
MsgBox " To print the comments, choose" & vbCrLf & _
" File|Page Setup|Sheet|Comments," & vbCrLf & _
"then choose the required print option.", vbOKOnly
End Sub

Cheers


"SueJB" wrote in message
...
Hi all,

Can anyone help with a strange quirk? I have a spreadsheet with a

series
of
numbers which have to be formatted to 1 decimal place. These show

fine in
"normal" mode.

If I display formulae, some of the cells not containing formulae lose

their
formatting - numbers with a decimal part are still shown to one place

(eg
1.6) but those without lose the decimal (eg 1 not 1.0). All attempts

to
change the formatting fail.

I need to be able to print the spreadsheet with formulae but also with
values displayed to one d.p. and I'm currently beaten.

Can anyone advise?

Thanks
SueJB






  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
SueJB
 
Posts: n/a
Default Displaying formulae changes formatting

Aah, I see ... many thanks, I'll try this.

Best wishes
SueJB

"macropod" wrote:

Hi Sue,

When Excel's displaying formulae, it can't display both the formula and
result for a given cell (at least with Excel 2000 and earlier). Any cells
with values are simply displayed as per the raw data (eg dates get converted
to numbers, decimal values get truncated at the last non-zero value, etc.).

With the macro I posted, you can display both the formula and it's result,
without compromising any of the value formatting. If you want to have both
the formula and its result appear in the same cell, you could increase the
row height, and re-position the comment in code to put it within the cell
and above/below the value, or you could increase the column width and put
the formula beside the result. If you don't want the formula's result to
show, re-position the comment in code to put it over the result.
repositioning the comment is managed by changing the values in the lines:
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25

Cheers


"SueJB" wrote in message
...
Hi macropod

Many thanks for replying. This is certainly an interesting way of

resolving
the problem, but unfortunately the spreadsheet must be printed with the
formulae in the relevant cells and the values in the non-formula cells
showing to one decimal place.

Thanks for your suggestion, though, much appreciated.

SueJB

"macropod" wrote:

Hi Sue,

The following macro adds the formulae to the comments for each selected
cell, or even the whole worksheet, and displays the comments in an
appropriately-sized comment box. This should allow you to both display

the
formulae and their results. Depending on what you're trying to achieve,

and
how crowded your worksheet is, you may still need to do a bit of
reformatting, and maybe get the macro the position the comments

differently,
but showing/hiding the formulae will then be as easy as toggling the

comment
display on/off.

Sub AddFormulaToComment()
Dim CommentRange As Range, TargetCell As Range
'skip over errors caused by trying to delete comments in cells with no
comments
On Error Resume Next
'If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
'If the cell contains a formula, make it a comment.
For Each TargetCell In CommentRange
With TargetCell
'check whether the cell has a formula
If Left(.Formula, 1) = "=" Then
'delete any existing comment
.Comment.Delete
'add a new comment
.AddComment
'copy the formula into the comment box
.Comment.Text Text:=.Formula
'display the comment
.Comment.Visible = True
With .Comment.Shape
'automatically resizes the comment
.TextFrame.AutoSize = True
'position the comment adjacent to its cell
If TargetCell.Column < 254 Then .IncrementLeft -11.25
If TargetCell.Row < 1 Then .IncrementTop 8.25
End With
End If
End With
Next
MsgBox " To print the comments, choose" & vbCrLf & _
" File|Page Setup|Sheet|Comments," & vbCrLf & _
"then choose the required print option.", vbOKOnly
End Sub

Cheers


"SueJB" wrote in message
...
Hi all,

Can anyone help with a strange quirk? I have a spreadsheet with a

series
of
numbers which have to be formatted to 1 decimal place. These show

fine in
"normal" mode.

If I display formulae, some of the cells not containing formulae lose
their
formatting - numbers with a decimal part are still shown to one place

(eg
1.6) but those without lose the decimal (eg 1 not 1.0). All attempts

to
change the formatting fail.

I need to be able to print the spreadsheet with formulae but also with
values displayed to one d.p. and I'm currently beaten.

Can anyone advise?

Thanks
SueJB






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel does not displaying formatting correctly Cookie Excel Discussion (Misc queries) 2 April 24th 06 02:55 PM
Formatting Cell Using Formulae....advise please.... Dermot Excel Discussion (Misc queries) 7 December 9th 05 08:35 PM
Nested functions in conditional formatting formulae Joseph Excel Discussion (Misc queries) 3 October 20th 05 11:52 PM
Excel 2002: I get formulae displaying in cells rather than value Matilda Excel Worksheet Functions 2 May 6th 05 12:02 AM
Formulae, conditional formatting & macro security Kevin Lucas Excel Discussion (Misc queries) 7 March 15th 05 01:10 PM


All times are GMT +1. The time now is 09:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"