PC Review


Reply
Thread Tools Rate Thread

Convert Macro to custom function

 
 
Chad
Guest
Posts: n/a
 
      25th Feb 2010
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
 
Reply With Quote
 
 
 
 
Chad
Guest
Posts: n/a
 
      25th Feb 2010
Hi Joel

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

Chad
 
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
custom function to convert numbers stored as text Josh Craig Microsoft Excel Programming 4 28th Jan 2010 05:23 AM
Convert MS-Word macro to an Access function =?Utf-8?B?TEY=?= Microsoft Access VBA Modules 1 22nd Feb 2007 03:49 PM
Using a custom function in a macro betty77 Microsoft Excel Programming 3 13th Aug 2006 12:32 PM
Convert Excel Functions to VBA Macro Function Simon Corner Microsoft Excel Programming 3 2nd Apr 2004 11:58 AM
I need a macro to convert my date formats into a custom layout. Martyn Microsoft Excel Programming 4 25th Feb 2004 12:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:46 PM.