Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
custom function to convert numbers stored as text | Excel Programming | |||
Using a custom function in a macro | Excel Programming | |||
I need a macro to convert my date formats into a custom layout. | Excel Programming | |||
I need a macro to convert my date formats into a custom layout. | Excel Programming | |||
Custom button and macro function | Excel Programming |