Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2013, 11:07 PM
macropod's Avatar
macropod macropod is offline Can a function or sub be called using a variable name? Windows 7 32bit Can a function or sub be called using a variable name? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Here's a simple demo of a Function taking an argument. The UDF below can use a formula like ‘=Ordinal (A1)’ or or ‘=Ordinal(37)’ for any cell on any worksheet to which the event-driven code is attached.


Code:
Function Ordinal(ByVal Num As Long) As Long
Ordinal = Num
End Function
 
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
  If UCase(Cell.Formula) Like "=ORDINAL(?*)" Then
    Cell.NumberFormat = "#""" & Mid$("thstndrdthththththth", 1 - 2 * _
      ((Cell.Value) Mod 10) * (Abs((Cell.Value) Mod 100 - 12) > 1), 2) & """"
  End If
Next
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 12-03-2013, 11:08 AM
omahadivision omahadivision is offline Can a function or sub be called using a variable name? Windows 7 32bit Can a function or sub be called using a variable name? Office 2007
Novice
Can a function or sub be called using a variable name?
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default

Thanks! I think I understand it except for the "Then" statement. Is that specific to a certain macro?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a function or sub be called using a variable name? object variable or with block variable not set MJP143 Excel 1 02-11-2013 05:07 AM
Can a function or sub be called using a variable name? Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM
excel where is procedure being called from davids67 Excel Programming 1 11-18-2011 06:48 AM
Can a function or sub be called using a variable name? What is this symbol called as? Franky Word 3 11-12-2011 08:16 AM
What is this right-click sub-menu called? wornways Word 3 08-13-2010 09:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft