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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Convert Macro into UDF

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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Convert Macro into UDF

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" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Convert Macro into UDF

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" wrote in message
...
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
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
convert a Word macro to an Excel macro jsd219 Excel Programming 32 October 27th 06 03:58 PM
Macro to convert CSV to PRN fugazi48 Excel Programming 2 October 5th 06 02:41 AM
Convert Macro ..... rvillanueva[_8_] Excel Programming 2 May 2nd 06 07:42 PM
Convert to .PDF macro Ashish[_3_] Excel Programming 1 October 3rd 05 01:46 PM
Using Macro to convert 240 to PRN Kenneth Excel Programming 1 November 9th 03 11:43 PM


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