Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bud Bud is offline
external usenet poster
 
Posts: 61
Default Sub or Function not defined message on finding Length

Hello

I am trying to get the Length of how many characters there are of the first
word in a task description.
However, I am getting a Sub or Function not defined message.
What is this about?
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1


The first word in the location of the cell offset(Task description) above
holds an abreviated change request number. First 3 characters are PRJ and
than the rest of it is the actual number less zero filling after the PRJ. It
will never be greater than 11 characters but the rule was to code it in the
first word as PRJ686 or PRJ1001. So I have to make this into PRJ00000686 and
PRJ00001001.

I have the whole construct of the code below to do this

Sheets("Fill-Down").Select
Cells.Select
Columns("e:e").Select
Dim Cell2 As Range

For Each Cell2 In Selection
If WorksheetFunction.IsNA(Cell2.Value) Then
'If Cell2.Value = "#N/A" Then
If Cell2.Offset(0, -1).Value = "General Admin - LA" Then
Cell2.Value = "0"
Cell2.Offset(0, 1).Value = "AD"
ElseIf Cell2.Offset(0, -1).Value = "Catalog - Help Desk Support" Then
Cell2.Value = "PRJ00000513"
Cell2.Offset(0, 1).Value = "HD"
ElseIf Left(Cell2.Offset(0, -1).Value, 3) = "PRJ" Then
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1
If Lenth = 6 Then
Cell2.Value = "PRJ00000" & Mid(Cell2.Offset(0, -1).Value,
4, 3)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 7 Then
Cell2.Value = "PRJ0000" & Mid(Cell2.Offset(0, -1).Value,
4, 4)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 8 Then
Cell2.Value = "PRJ000" & Mid(Cell2.Offset(0, -1).Value, 4,
5)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 9 Then
Cell2.Value = "PRJ00" & Mid(Cell2.Offset(0, -1).Value, 4, 6)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 10 Then
Cell2.Value = "PRJ0" & Mid(Cell2.Offset(0, -1).Value, 4, 7)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 11 Then
Cell2.Value = "PRJ" & Mid(Cell2.Offset(0, -1).Value, 4, 8)
Cell2.Offset(0, 1).Value = "EN"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Sub or Function not defined message on finding Length

Bud,

Fins isn't a VB function so you have to do this

Lenth = WorksheetFunction.Find(" ", Cell2.Offset(0, -1).Value, 1) - 1

Mike

"Bud" wrote:

Hello

I am trying to get the Length of how many characters there are of the first
word in a task description.
However, I am getting a Sub or Function not defined message.
What is this about?
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1


The first word in the location of the cell offset(Task description) above
holds an abreviated change request number. First 3 characters are PRJ and
than the rest of it is the actual number less zero filling after the PRJ. It
will never be greater than 11 characters but the rule was to code it in the
first word as PRJ686 or PRJ1001. So I have to make this into PRJ00000686 and
PRJ00001001.

I have the whole construct of the code below to do this

Sheets("Fill-Down").Select
Cells.Select
Columns("e:e").Select
Dim Cell2 As Range

For Each Cell2 In Selection
If WorksheetFunction.IsNA(Cell2.Value) Then
'If Cell2.Value = "#N/A" Then
If Cell2.Offset(0, -1).Value = "General Admin - LA" Then
Cell2.Value = "0"
Cell2.Offset(0, 1).Value = "AD"
ElseIf Cell2.Offset(0, -1).Value = "Catalog - Help Desk Support" Then
Cell2.Value = "PRJ00000513"
Cell2.Offset(0, 1).Value = "HD"
ElseIf Left(Cell2.Offset(0, -1).Value, 3) = "PRJ" Then
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1
If Lenth = 6 Then
Cell2.Value = "PRJ00000" & Mid(Cell2.Offset(0, -1).Value,
4, 3)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 7 Then
Cell2.Value = "PRJ0000" & Mid(Cell2.Offset(0, -1).Value,
4, 4)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 8 Then
Cell2.Value = "PRJ000" & Mid(Cell2.Offset(0, -1).Value, 4,
5)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 9 Then
Cell2.Value = "PRJ00" & Mid(Cell2.Offset(0, -1).Value, 4, 6)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 10 Then
Cell2.Value = "PRJ0" & Mid(Cell2.Offset(0, -1).Value, 4, 7)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 11 Then
Cell2.Value = "PRJ" & Mid(Cell2.Offset(0, -1).Value, 4, 8)
Cell2.Offset(0, 1).Value = "EN"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Sub or Function not defined message on finding Length

I think I'd use INSTR for this

Lenth = InStr(1, Cell2.Offset(0, -1).Value, " ") - 1

'Check for Lenth = -1 meaning you haven't found anything

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Bud" wrote:

Hello

I am trying to get the Length of how many characters there are of the first
word in a task description.
However, I am getting a Sub or Function not defined message.
What is this about?
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1


The first word in the location of the cell offset(Task description) above
holds an abreviated change request number. First 3 characters are PRJ and
than the rest of it is the actual number less zero filling after the PRJ. It
will never be greater than 11 characters but the rule was to code it in the
first word as PRJ686 or PRJ1001. So I have to make this into PRJ00000686 and
PRJ00001001.

I have the whole construct of the code below to do this

Sheets("Fill-Down").Select
Cells.Select
Columns("e:e").Select
Dim Cell2 As Range

For Each Cell2 In Selection
If WorksheetFunction.IsNA(Cell2.Value) Then
'If Cell2.Value = "#N/A" Then
If Cell2.Offset(0, -1).Value = "General Admin - LA" Then
Cell2.Value = "0"
Cell2.Offset(0, 1).Value = "AD"
ElseIf Cell2.Offset(0, -1).Value = "Catalog - Help Desk Support" Then
Cell2.Value = "PRJ00000513"
Cell2.Offset(0, 1).Value = "HD"
ElseIf Left(Cell2.Offset(0, -1).Value, 3) = "PRJ" Then
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1
If Lenth = 6 Then
Cell2.Value = "PRJ00000" & Mid(Cell2.Offset(0, -1).Value,
4, 3)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 7 Then
Cell2.Value = "PRJ0000" & Mid(Cell2.Offset(0, -1).Value,
4, 4)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 8 Then
Cell2.Value = "PRJ000" & Mid(Cell2.Offset(0, -1).Value, 4,
5)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 9 Then
Cell2.Value = "PRJ00" & Mid(Cell2.Offset(0, -1).Value, 4, 6)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 10 Then
Cell2.Value = "PRJ0" & Mid(Cell2.Offset(0, -1).Value, 4, 7)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 11 Then
Cell2.Value = "PRJ" & Mid(Cell2.Offset(0, -1).Value, 4, 8)
Cell2.Offset(0, 1).Value = "EN"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Sub or Function not defined message on finding Length

you could do the following

Public Function reCode(ByVal acode As Range) As String

scode = Split(acode.Value2, " ")(0) '<-- The first element using space
as spliiter
sPref = "PRJ"
sNum = Right(scode, Len(scode) - 3) '<--- Remove PRJ
sNewNum = WorksheetFunction.Rept("0", 8 - Len(sNum)) & sNum
remakecode = sPref & sNewNum


End Function

"Mike H" wrote:

Bud,

Fins isn't a VB function so you have to do this

Lenth = WorksheetFunction.Find(" ", Cell2.Offset(0, -1).Value, 1) - 1

Mike

"Bud" wrote:

Hello

I am trying to get the Length of how many characters there are of the first
word in a task description.
However, I am getting a Sub or Function not defined message.
What is this about?
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1


The first word in the location of the cell offset(Task description) above
holds an abreviated change request number. First 3 characters are PRJ and
than the rest of it is the actual number less zero filling after the PRJ. It
will never be greater than 11 characters but the rule was to code it in the
first word as PRJ686 or PRJ1001. So I have to make this into PRJ00000686 and
PRJ00001001.

I have the whole construct of the code below to do this

Sheets("Fill-Down").Select
Cells.Select
Columns("e:e").Select
Dim Cell2 As Range

For Each Cell2 In Selection
If WorksheetFunction.IsNA(Cell2.Value) Then
'If Cell2.Value = "#N/A" Then
If Cell2.Offset(0, -1).Value = "General Admin - LA" Then
Cell2.Value = "0"
Cell2.Offset(0, 1).Value = "AD"
ElseIf Cell2.Offset(0, -1).Value = "Catalog - Help Desk Support" Then
Cell2.Value = "PRJ00000513"
Cell2.Offset(0, 1).Value = "HD"
ElseIf Left(Cell2.Offset(0, -1).Value, 3) = "PRJ" Then
Lenth = Find(" ", Cell2.Offset(0, -1).Value, 1) - 1
If Lenth = 6 Then
Cell2.Value = "PRJ00000" & Mid(Cell2.Offset(0, -1).Value,
4, 3)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 7 Then
Cell2.Value = "PRJ0000" & Mid(Cell2.Offset(0, -1).Value,
4, 4)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 8 Then
Cell2.Value = "PRJ000" & Mid(Cell2.Offset(0, -1).Value, 4,
5)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 9 Then
Cell2.Value = "PRJ00" & Mid(Cell2.Offset(0, -1).Value, 4, 6)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 10 Then
Cell2.Value = "PRJ0" & Mid(Cell2.Offset(0, -1).Value, 4, 7)
Cell2.Offset(0, 1).Value = "EN"
ElseIf Lenth = 11 Then
Cell2.Value = "PRJ" & Mid(Cell2.Offset(0, -1).Value, 4, 8)
Cell2.Offset(0, 1).Value = "EN"

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 Message "user defined type not defined" LEELK01 Excel Discussion (Misc queries) 2 August 14th 09 07:31 AM
Finding cells of different string length. kingie Excel Discussion (Misc queries) 5 March 13th 08 12:31 AM
Finding the length of proportional text strings Russ Excel Programming 7 February 13th 07 12:11 AM
Help finding the length of two different columns willz99ta via OfficeKB.com Excel Programming 4 March 17th 06 05:13 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM


All times are GMT +1. The time now is 06:13 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"