PC Review


Reply
Thread Tools Rate Thread

function returning Text to cell

 
 
John
Guest
Posts: n/a
 
      27th Mar 2007
First thanks for taking the time to help a poor soul out.
Here is my issue.
I have a list of vendor names. The vendor names are some what of an
abbreviation of the actual name. I want to write a function that will
take in the range of Vendor abbreviations and replace it with the
full
name. I thought a 'Select Case' would be easiest. I also would like to
return the name to the cell itself not another cell. The cell is not
turning red either. Here is my code :
Function ConvertVenName(Ven As Range) As String
Dim xlCalc As XlCalculation
Dim savScrnUD As Boolean
savScrnUD = Application.ScreenUpdating
Application.ScreenUpdating = True
xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual
On Error GoTo CalcBack
Select Case Ven.Value
Case "3D ventures"
ConvertVenName = "3-D Ventures Ltd."
Case Else
Ven.Interior.Color = vbRed
End Select

Application.Calculation = xlCalc
Application.ScreenUpdating = savScrnUD
Exit Function
CalcBack:
MsgBox Err.Description
Application.Calculation = xlCalc
Application.ScreenUpdating = savScrnUD
End Function

cheers
John

 
Reply With Quote
 
 
 
 
Earl Kiosterud
Guest
Posts: n/a
 
      28th Mar 2007
John,

A function can only return a value, and only where it appears. So the abbreviation would
have to be on one cell (A2, mayhaps), and =ConvertVenName(A2) in another (e.g.: B2). In B2,
you'd see the returned value of the function. But it can't do stuff like change the cell
formatting (color). Also, using a Select Case isn't the normal practice, especially where
the abbreviations and corresponding full names might change.

If you want to change the abbreviations in situ (A2), you could use AutoCorrect, or an
event-fired sub (Worksheet_Change) that changes them as soon as they're typed in. If you
want to put the abbreviations in one cell (A2) and see the corresponding full name in
another (B2), make a table of the abbreviations somewhere and in B2, use =VLOOKUP(A2, Table,
2, FALSE).

--
Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> First thanks for taking the time to help a poor soul out.
> Here is my issue.
> I have a list of vendor names. The vendor names are some what of an
> abbreviation of the actual name. I want to write a function that will
> take in the range of Vendor abbreviations and replace it with the
> full
> name. I thought a 'Select Case' would be easiest. I also would like to
> return the name to the cell itself not another cell. The cell is not
> turning red either. Here is my code :
> Function ConvertVenName(Ven As Range) As String
> Dim xlCalc As XlCalculation
> Dim savScrnUD As Boolean
> savScrnUD = Application.ScreenUpdating
> Application.ScreenUpdating = True
> xlCalc = Application.Calculation
> Application.Calculation = xlCalculationManual
> On Error GoTo CalcBack
> Select Case Ven.Value
> Case "3D ventures"
> ConvertVenName = "3-D Ventures Ltd."
> Case Else
> Ven.Interior.Color = vbRed
> End Select
>
> Application.Calculation = xlCalc
> Application.ScreenUpdating = savScrnUD
> Exit Function
> CalcBack:
> MsgBox Err.Description
> Application.Calculation = xlCalc
> Application.ScreenUpdating = savScrnUD
> End Function
>
> cheers
> John
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Function returning 0 instead of cell value torana_girl77 Microsoft Excel Worksheet Functions 4 6th May 2009 06:03 AM
Returning newline from a function to a cell Dave Dixson Microsoft Excel Programming 2 22nd Aug 2006 02:19 PM
Returning a tooltip function for datagrid cell. Is it possible =?Utf-8?B?U3RlcGhlbg==?= Microsoft C# .NET 1 6th Apr 2005 04:53 PM
Returning a tooltip for a datagrid cell using a function? Is it po =?Utf-8?B?U3RlcGhlbg==?= Microsoft Dot NET 0 6th Apr 2005 01:07 PM
returning a text cell based on a number cell Josh7777777 Microsoft Excel Worksheet Functions 2 2nd Nov 2004 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 PM.