Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Convert Macro to custom function

Hi

I would like to convert this macro to a custom function. Basically
what I would like to do is recreate a vlookup in a custom function. I
want to say If the cell the vlookup points to is either A, B, C or D
then do one thing, else do another.

Here is the code which works in a normal macro. I would like a
function where I could go

=checkit(A1,True Value here, False Value here)

Thanks in advance.

Chad



Sub Checkit()

Dim RngCell As Range
Dim MyList() As Variant
Dim res As Variant
Dim Last As Long
Dim X As Range
Dim ws As Worksheet


Last = Range("B" & Rows.Count).End(xlUp).Row
MyList() = Array("A", "B", "C", "D")

Set X = Range("B2:B" & Last)
For Each RngCell In X
res = Application.Match(RngCell.Value, MyList, 0)
If IsError(res) Then
'One thing here
Else
'Another here
End If
Next RngCell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Convert Macro to custom function


Function Checkit(target as Range, MatchResults as String,
NonMatchResults as String)

Select Case Target
Case "A","B","C","D"
Checkit = MatchResults
case Else
Checkit = NonMatchResults
end select

End Function


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=182445

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Convert Macro to custom function

Hi Joel

This is really good. Thank you so much for your help. Have a good
day.

Chad
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
custom function to convert numbers stored as text Josh Craig Excel Programming 4 January 28th 10 05:23 AM
Using a custom function in a macro betty77[_6_] Excel Programming 3 August 13th 06 12:32 PM
I need a macro to convert my date formats into a custom layout. Martyn Excel Programming 0 February 25th 04 12:37 PM
I need a macro to convert my date formats into a custom layout. Martyn Excel Programming 0 February 25th 04 12:29 PM
Custom button and macro function Andy Excel Programming 4 October 7th 03 07:25 PM


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