PC Review


Reply
Thread Tools Rate Thread

Convert Macro into UDF

 
 
Dylan
Guest
Posts: n/a
 
      16th Jul 2008
I would like to convert a macro into a UDF to make my sheet automatically
update, and also because I haven't used UDFs and would like to learn about
them.

The macro looks up the value of one cell and depending on the string adds a
text string to the another cell.

Sub Update_CEStatus()

Dim myC2 As Range
Dim WatchRange2 As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Set WatchRange2 = Range("Status")
On Error Resume Next

For Each myC2 In WatchRange2
If myC2.Cells.Value = "" _
Or myC2.Cells.Value = "Complete" _
Or myC2.Cells.Value = "Cancelled" Then
myC2.Offset(0, 1).Value = "Complete"

ElseIf myC2.Cells.Value = "Forecast" _
Or myC2.Cells.Value = "Awaiting Budget Quote" _
Or myC2.Cells.Value = "Awaiting Firm Quote" Then
myC2.Offset(0, 1).Value = "Ongoing"

End If
Next myC2

With Application
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
End Sub

Regards
Dylan

 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Jul 2008
Dylan,

Function CEStatus(myC2 As Range) As String
CEStatus = ""
If myC2.Value = "" _
Or myC2.Value = "Complete" _
Or myC2.Value = "Cancelled" Then _
CEStatus = "Complete"
If myC2.Value = "Forecast" _
Or myC2.Value = "Awaiting Budget Quote" _
Or myC2.Value = "Awaiting Firm Quote" Then _
CEStatus = "Ongoing"
End Function


Used like

=CEStatus(A1)

--
HTH,
Bernie
MS Excel MVP


"Dylan" <(E-Mail Removed)> wrote in message
news:8E86DA59-BBA1-43C4-852E-(E-Mail Removed)...
>I would like to convert a macro into a UDF to make my sheet automatically
> update, and also because I haven't used UDFs and would like to learn about
> them.
>
> The macro looks up the value of one cell and depending on the string adds a
> text string to the another cell.
>
> Sub Update_CEStatus()
>
> Dim myC2 As Range
> Dim WatchRange2 As Range
>
> With Application
> .ScreenUpdating = False
> .Calculation = xlCalculationManual
> End With
> Set WatchRange2 = Range("Status")
> On Error Resume Next
>
> For Each myC2 In WatchRange2
> If myC2.Cells.Value = "" _
> Or myC2.Cells.Value = "Complete" _
> Or myC2.Cells.Value = "Cancelled" Then
> myC2.Offset(0, 1).Value = "Complete"
>
> ElseIf myC2.Cells.Value = "Forecast" _
> Or myC2.Cells.Value = "Awaiting Budget Quote" _
> Or myC2.Cells.Value = "Awaiting Firm Quote" Then
> myC2.Offset(0, 1).Value = "Ongoing"
>
> End If
> Next myC2
>
> With Application
> .ScreenUpdating = False
> .Calculation = xlCalculationAutomatic
> End With
> End Sub
>
> Regards
> Dylan
>



 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      16th Jul 2008
Just some FYI for the OP,

Here is a source of additional information:

http://www.cpearson.com/Excel/Writin...ionsInVBA.aspx

--
Regards,
Tom Ogilvy


"Bernie Deitrick" wrote:

> Dylan,
>
> Function CEStatus(myC2 As Range) As String
> CEStatus = ""
> If myC2.Value = "" _
> Or myC2.Value = "Complete" _
> Or myC2.Value = "Cancelled" Then _
> CEStatus = "Complete"
> If myC2.Value = "Forecast" _
> Or myC2.Value = "Awaiting Budget Quote" _
> Or myC2.Value = "Awaiting Firm Quote" Then _
> CEStatus = "Ongoing"
> End Function
>
>
> Used like
>
> =CEStatus(A1)
>
> --
> HTH,
> Bernie
> MS Excel MVP
>
>
> "Dylan" <(E-Mail Removed)> wrote in message
> news:8E86DA59-BBA1-43C4-852E-(E-Mail Removed)...
> >I would like to convert a macro into a UDF to make my sheet automatically
> > update, and also because I haven't used UDFs and would like to learn about
> > them.
> >
> > The macro looks up the value of one cell and depending on the string adds a
> > text string to the another cell.
> >
> > Sub Update_CEStatus()
> >
> > Dim myC2 As Range
> > Dim WatchRange2 As Range
> >
> > With Application
> > .ScreenUpdating = False
> > .Calculation = xlCalculationManual
> > End With
> > Set WatchRange2 = Range("Status")
> > On Error Resume Next
> >
> > For Each myC2 In WatchRange2
> > If myC2.Cells.Value = "" _
> > Or myC2.Cells.Value = "Complete" _
> > Or myC2.Cells.Value = "Cancelled" Then
> > myC2.Offset(0, 1).Value = "Complete"
> >
> > ElseIf myC2.Cells.Value = "Forecast" _
> > Or myC2.Cells.Value = "Awaiting Budget Quote" _
> > Or myC2.Cells.Value = "Awaiting Firm Quote" Then
> > myC2.Offset(0, 1).Value = "Ongoing"
> >
> > End If
> > Next myC2
> >
> > With Application
> > .ScreenUpdating = False
> > .Calculation = xlCalculationAutomatic
> > End With
> > End Sub
> >
> > Regards
> > Dylan
> >

>
>
>

 
Reply With Quote
 
Dylan
Guest
Posts: n/a
 
      16th Jul 2008
Thanks guys, this is a lot neater than my previous macro.

I need to consider using these in future.

Regards
Dylan

"Tom Ogilvy" wrote:

> Just some FYI for the OP,
>
> Here is a source of additional information:
>
> http://www.cpearson.com/Excel/Writin...ionsInVBA.aspx
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Bernie Deitrick" wrote:
>
> > Dylan,
> >
> > Function CEStatus(myC2 As Range) As String
> > CEStatus = ""
> > If myC2.Value = "" _
> > Or myC2.Value = "Complete" _
> > Or myC2.Value = "Cancelled" Then _
> > CEStatus = "Complete"
> > If myC2.Value = "Forecast" _
> > Or myC2.Value = "Awaiting Budget Quote" _
> > Or myC2.Value = "Awaiting Firm Quote" Then _
> > CEStatus = "Ongoing"
> > End Function
> >
> >
> > Used like
> >
> > =CEStatus(A1)
> >
> > --
> > HTH,
> > Bernie
> > MS Excel MVP
> >
> >
> > "Dylan" <(E-Mail Removed)> wrote in message
> > news:8E86DA59-BBA1-43C4-852E-(E-Mail Removed)...
> > >I would like to convert a macro into a UDF to make my sheet automatically
> > > update, and also because I haven't used UDFs and would like to learn about
> > > them.
> > >
> > > The macro looks up the value of one cell and depending on the string adds a
> > > text string to the another cell.
> > >
> > > Sub Update_CEStatus()
> > >
> > > Dim myC2 As Range
> > > Dim WatchRange2 As Range
> > >
> > > With Application
> > > .ScreenUpdating = False
> > > .Calculation = xlCalculationManual
> > > End With
> > > Set WatchRange2 = Range("Status")
> > > On Error Resume Next
> > >
> > > For Each myC2 In WatchRange2
> > > If myC2.Cells.Value = "" _
> > > Or myC2.Cells.Value = "Complete" _
> > > Or myC2.Cells.Value = "Cancelled" Then
> > > myC2.Offset(0, 1).Value = "Complete"
> > >
> > > ElseIf myC2.Cells.Value = "Forecast" _
> > > Or myC2.Cells.Value = "Awaiting Budget Quote" _
> > > Or myC2.Cells.Value = "Awaiting Firm Quote" Then
> > > myC2.Offset(0, 1).Value = "Ongoing"
> > >
> > > End If
> > > Next myC2
> > >
> > > With Application
> > > .ScreenUpdating = False
> > > .Calculation = xlCalculationAutomatic
> > > End With
> > > End Sub
> > >
> > > Regards
> > > Dylan
> > >

> >
> >
> >

 
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
how to convert 123- to -1.23 with a macro cheri gemini Microsoft Excel Programming 6 10th Nov 2009 03:10 AM
Convert macro to VB Yousoft Microsoft Access Macros 1 1st Dec 2008 07:48 PM
convert a Word macro to an Excel macro jsd219 Microsoft Excel Programming 24 27th Oct 2006 03:58 PM
Convert Macro ..... rvillanueva Microsoft Excel Programming 2 2nd May 2006 07:42 PM
Convert to .PDF macro Ashish Microsoft Excel Programming 1 3rd Oct 2005 01:46 PM


Features
 

Advertising
 

Newsgroups
 


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