Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default SUMIF in Visual Basic Function

Can anyone translate the excel function SUMIF into Visual Basic Function
format ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default SUMIF in Visual Basic Function

Dim var as Integer
var = 0
Do
If MyCondition = True Then
var = var + 1
Loop

Debug.Print var

'MH

"magix" wrote in message ...
Can anyone translate the excel function SUMIF into Visual Basic Function
format ?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default SUMIF in Visual Basic Function

The excel always complaint about circular references. how can i prevent that
?
If I use Application.WorksheetFunction.SumIf:
C1 = Application.WorksheetFunction.SumIf...

then I will get the alert of Circular reference. Why ? and How to get rid of
?


I need the value of SUMIF from C1 - C5, in order to compare with R1-R5

My code is as below:


Function CheckSession(S1 As String, S2 As String, S3 As String, S4 As
String, S5 As String, R1 As Integer, R2 As Integer, R3 As Integer, R4 As
Integer, R5 As Integer) As String


Dim Session As String
Dim C1 As Integer
Dim C2 As Integer
Dim C3 As Integer
Dim C4 As Integer
Dim C5 As Integer

C1 = Application.WorksheetFunction.SumIf(Range("AL5:AL3 807"), "1",
Range("AP5:AP3807"))
C2 = Application.WorksheetFunction.SumIf(Range("AL5:AL3 807"), "2",
Range("AP5:AP3807"))
C3 = Application.WorksheetFunction.SumIf(Range("AL5:AL3 807"), "3",
Range("AP5:AP3807"))
C4 = Application.WorksheetFunction.SumIf(Range("AL5:AL3 807"), "4",
Range("AP5:AP3807"))
C5 = Application.WorksheetFunction.SumIf(Range("AL5:AL3 807"), "5",
Range("AP5:AP3807"))


Session = ""

If ((S1 < "CLOSED") And (S1 < "N/A")) Then
If C1 < R1 Then
Session = S1
End If
End If
If ((S2 < "CLOSED") And (S2 < "N/A")) Then
If C2 < R2 Then
If Session = "" Then
Session = S2
Else
If Val(Session) Val(S2) Then
Session = S2
End If
End If
End If
End If

...
...

CheckSession = Session
End Function



"MH" wrote in message
...
Dim var as Integer
var = 0
Do
If MyCondition = True Then
var = var + 1
Loop

Debug.Print var

'MH

"magix" wrote in message
...
Can anyone translate the excel function SUMIF into Visual Basic Function
format ?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default SUMIF in Visual Basic Function


Sub DoItLikeSumIf()
Dim dblAnswer As Double
dblAnswer = Application.WorksheetFunction.SumIf(Range("B5:B10" ), _
"=Mush", Range("D5:D10"))
MsgBox dblAnswer
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"magix"
wrote in message
Can anyone translate the excel function SUMIF into Visual Basic Function
format ?


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
How should I do this (function or Visual basic) Pasi[_2_] Excel Worksheet Functions 5 November 24th 08 07:42 PM
Call a Visual Basic Function with VLookup ajd Excel Worksheet Functions 10 December 18th 07 03:40 AM
End of Month Function in Visual Basic Fredriksson via OfficeKB.com Excel Programming 4 January 25th 07 03:06 PM
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
How do I use an array function in Visual basic .NET? cirrus Excel Programming 1 October 22nd 04 04:23 PM


All times are GMT +1. The time now is 12:30 PM.

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"