Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Function to display a cell containing an underlined number

I have a cell with some formatting (an underlined digit) on one worksheet and
I would like to display it on another worksheet.

Why won't the following code display the cell. The line inside the "IF"
complains that "A value used in the formula is of the wrong type".

I've tried many variations of this but this one I think gets the point across.

Function CopyNumberWithOneUnderlinedCharacter(ByVal myCell As Range)
Dim l_Position As Integer
For l_Position = 1 To Len(myCell.Value)
If myCell.Characters(Start:=l_Position, Length:=1).Font.Underline _
< xlUnderlineStyleNone Then

CopyNumberWithOneUnderlinedCharacter.Characters(St art:=l_Position,
Length:=1).Font.Underline = xlUnderlineStyleSingle
End If
Next l_Position
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Function to display a cell containing an underlined number

Hi,

does it have to be a function? A function usually returns a value, it does
not manipulate cells (i.e. adding format etc). I suggest the following
procedure instead, for which you can create a button that will execute it.

Sub copy()
Dim source As Range, dest As Range
Dim sourceName As String, destName As String

sourceName = InputBox("Source cell: ")
destName = InputBox("Destination cell: ")

Set source = Range(sourceName)
Set dest = Range(destName)

dest = source
dest.Font.Underline = xlUnderlineStyleSingle
dest.NumberFormat = "0"


End Sub

Regards,

Alex


"jquiet" wrote:

I have a cell with some formatting (an underlined digit) on one worksheet and
I would like to display it on another worksheet.

Why won't the following code display the cell. The line inside the "IF"
complains that "A value used in the formula is of the wrong type".

I've tried many variations of this but this one I think gets the point across.

Function CopyNumberWithOneUnderlinedCharacter(ByVal myCell As Range)
Dim l_Position As Integer
For l_Position = 1 To Len(myCell.Value)
If myCell.Characters(Start:=l_Position, Length:=1).Font.Underline _
< xlUnderlineStyleNone Then

CopyNumberWithOneUnderlinedCharacter.Characters(St art:=l_Position,
Length:=1).Font.Underline = xlUnderlineStyleSingle
End If
Next l_Position
End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Function to display a cell containing an underlined number

Hi again,

Although the code I posted works, use the following, which is more correct
from an object-oriented perspective, just in case (I have changed the "dest =
source" for "dest.Value = source.Value"):

Sub copy()
Dim source As Range, dest As Range
Dim sourceName As String, destName As String

sourceName = InputBox("Source cell: ")
destName = InputBox("Destination cell: ")

Set source = Range(sourceName)
Set dest = Range(destName)

dest.Value = source.Value
dest.Font.Underline = xlUnderlineStyleSingle
dest.NumberFormat = "0"


End Sub



Regards,

Alex



"Alex Guardiet" wrote:

Hi,

does it have to be a function? A function usually returns a value, it does
not manipulate cells (i.e. adding format etc). I suggest the following
procedure instead, for which you can create a button that will execute it.

Sub copy()
Dim source As Range, dest As Range
Dim sourceName As String, destName As String

sourceName = InputBox("Source cell: ")
destName = InputBox("Destination cell: ")

Set source = Range(sourceName)
Set dest = Range(destName)

dest = source
dest.Font.Underline = xlUnderlineStyleSingle
dest.NumberFormat = "0"


End Sub

Regards,

Alex


"jquiet" wrote:

I have a cell with some formatting (an underlined digit) on one worksheet and
I would like to display it on another worksheet.

Why won't the following code display the cell. The line inside the "IF"
complains that "A value used in the formula is of the wrong type".

I've tried many variations of this but this one I think gets the point across.

Function CopyNumberWithOneUnderlinedCharacter(ByVal myCell As Range)
Dim l_Position As Integer
For l_Position = 1 To Len(myCell.Value)
If myCell.Characters(Start:=l_Position, Length:=1).Font.Underline _
< xlUnderlineStyleNone Then

CopyNumberWithOneUnderlinedCharacter.Characters(St art:=l_Position,
Length:=1).Font.Underline = xlUnderlineStyleSingle
End If
Next l_Position
End Function

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
Match Function And Display Row Number CecesWorking Excel Worksheet Functions 2 January 26th 09 04:25 PM
Function to find/display the date X number of days later? a0xbjzz Excel Worksheet Functions 1 October 26th 07 02:12 PM
display a number in another cell Motherlulu Excel Worksheet Functions 3 July 12th 07 03:32 PM
display text in one cell as a number in an adjacent cell in excel Denno New Users to Excel 1 November 16th 06 05:13 PM
Finding an underlined character among several characters in a cell jquiet Excel Programming 2 September 29th 04 12:43 AM


All times are GMT +1. The time now is 06:05 AM.

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"