LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Convert text value to numeric value in VBA

Hi,

I am having some big troubles with a quit simple VBA code.
It extracts 4 digit year number out of a text string.

The problem is that it returns the year as a text value no matter what
I do.
I have tried to use Val, Cdbl, multiply with 1 etc. but nothing helps.

I dont want to use the worhsheetfunction value in excel and it is not
valid in the VBE.
Nor either to mutiply with 1 in excel, which also works. This should
work with just this UDF!

Please help me!! See code below.

Function ExtractYear(MyFileName1 As String) As String
Dim AntalTegn, j As Integer

AntalTegn = Len(MyFileName1)
If AntalTegn = 0 Then
Exit Function
Else

For j = 1 To AntalTegn
If IsNumeric(Mid(MyFileName1, j, 1)) = True Then
If IsNumeric(Mid(MyFileName1, j, 4)) = True Then
ExtractYear = Mid(MyFileName1, j, 4)
'ExtractYear = ExtractYear.Value
Exit For
End If
End If
Next j
End If
End Function


Hope to hear from someone soon :-)

Cheers

Marc

 
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
Convert text to numeric value Dylan @ UAFC Excel Discussion (Misc queries) 1 May 15th 08 12:36 AM
Numeric in Text to convert back to the form of Numeric for VLookup Purposes achilles Excel Discussion (Misc queries) 4 February 6th 06 07:05 AM
convert text to numeric vba add-in? sulmau Excel Worksheet Functions 1 July 25th 05 08:41 PM
Convert Numeric into Text Monty Excel Worksheet Functions 0 December 18th 04 09:25 PM


All times are GMT +1. The time now is 08:55 PM.

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

About Us

"It's about Microsoft Excel"