LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Expressing If formula in VBA

Your code isn't working the way you think it is. Try putting the
entire IF statement on a single line of code:

If (r.Value = "06-00 Sunrise SEVEN Perth_Hits") Then ret = 131

Of, better, use a Select Case statement

Select Case r.Value
Case "06-00 Sunrise SEVEN Perth_Hits"
ret = 131
Case "06-00 Sunrise SEVEN Melbourne_Hits"
ret = 131
' rest of your Case statement
End Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Vlad999"
wrote in message
...

When I use the code below I get the following error message
"Compile
Error Block if Without End if" What have i done wrong?


Code:
--------------------

Function doCount(r)
Dim ret As Integer
If (r.Value = "06-00 Sunrise SEVEN Perth_Hits") Then
ret = 131
If (r.Value = "06-00 Sunrise SEVEN Melbourne_Hits") Then
ret = 131
If (r.Value = "06-00 Sunrise SEVEN Brisbane_Hits") Then
ret = 131
If (r.Value = "06-00 Sunrise SEVEN Adelaide_Hits") Then
ret = 131
If (r.Value = "06-00 Ten Early News TEN Sydney_Hits") Then
ret = 40
If (r.Value = "06-00 Ten Early News TEN Brisbane_Hits") Then
ret = 40
If (r.Value = "06-00 Ten Early News TEN Melbourne_Hits") Then
ret = 40
If (r.Value = "06-00 Ten Early News TEN Perth_Hits") Then
ret = 40
If (r.Value = "06-00 Ten Early News TEN Adelaide_Hits") Then
ret = 40
If (r.Value = "06-00 Today NINE Sydney_Hits") Then
ret = 110
If (r.Value = "06-00 Today NINE Melbourne_Hits") Then
ret = 110
If (r.Value = "06-00 Today NINE Brisbane_Hits") Then
ret = 110
If (r.Value = "06-00 Today NINE Adelaide_Hits") Then
ret = 110
If (r.Value = "06-00 Today NINE Perth_Hits") Then
ret = 110
If (r.Value = "17-00 Ten News TEN Sydney_Hits") Then
ret = 120
If (r.Value = "17-00 Ten News TEN Melbourne_Hits") Then
ret = 97
If (r.Value = "17-00 Ten News TEN Brisbane_Hits") Then
ret = 70
If (r.Value = "17-00 Ten News TEN Adelaide_Hits") Then
ret = 38
If (r.Value = "17-00 Ten News TEN Perth_Hits") Then
ret = 63
If (r.Value = "17-30 Sports Tonight TEN Sydney_Hits") Then
ret = 446
If (r.Value = "17-30 Sports Tonight TEN Melbourne_Hits") Then
ret = 446
If (r.Value = "17-30 Sports Tonight TEN Brisbane_Hits") Then
ret = 446
If (r.Value = "17-30 Sports Tonight TEN Adelaide_Hits") Then
ret = 446
If (r.Value = "17-30 Sports Tonight TEN Perth_Hits") Then
ret = 446
If (r.Value = "18-00 National Nine News NINE Sydney_Hits")
Then
ret = 326
If (r.Value = "18-00 National Nine News NINE Melbourne_Hits")
Then
ret = 261
If (r.Value = "18-00 National Nine News NINE Brisbane_Hits")
Then
ret = 169
If (r.Value = "18-00 National Nine News NINE Adelaide_Hits")
Then
ret = 77
If (r.Value = "18-00 National Nine News NINE Perth_Hits") Then
ret = 75
Else
ret = 0
End If

doCount = ret
End Function

--------------------


--
Vlad999
------------------------------------------------------------------------
Vlad999's Profile:
http://www.excelforum.com/member.php...o&userid=33586
View this thread:
http://www.excelforum.com/showthread...hreadid=544111



 
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
Need help with formula for expressing multiple greater/less than charlie Excel Discussion (Misc queries) 5 January 12th 09 06:53 PM
Expressing a number in words Karen Crozier Excel Discussion (Misc queries) 3 July 31st 07 03:42 PM
Expressing a number in words Mike D Excel Worksheet Functions 2 December 14th 06 06:43 PM
Expressing percentages in Excel John Hodgson Excel Discussion (Misc queries) 1 August 30th 06 12:09 AM
expressing minutes negatively DJ Excel Discussion (Misc queries) 3 March 14th 06 06:07 PM


All times are GMT +1. The time now is 04:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"