Formula to VB

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
I have the following formula:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
=IF(NETWORKDAYS(NOW(),G110)<1,1,IF(NETWORKDAYS(NOW(),G110)<=3,2,""))
<o:p> </o:p>
I need this in vb form where if the result of the first test is <1, I will add to a counter else if the result of the second test is <=3 I would add to another counter.
<o:p> </o:p>
Any help would be great….
<o:p> </o:p>
Many Thanks!!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Something like this, maybe:
Code:
Sub test()
Dim Cnt1 As Long, Cnt2 As Long

    Select Case Evaluate("NETWORKDAYS(Now(),G110)")
        Case Is < 1
            Cnt1 = Cnt1 + 1
        Case Is <= 3
            Cnt2 = Cnt2 + 1
    End Select

End Sub

The Cnt1 and Cnt2 could be replaced with a counter cell.
 
Upvote 0
I'm getting a Type mismatch during execution. I beleive it's because I am putting the value in a cell (cells(i,....) instead of the address of the cell.

Please let me know how I can change the statement to obtain my results.

Select Case Evaluate("NETWORKDAYS(Now(),Cells(i, RRptHD(RRptHDC7)))")
Case Is < 1
OIRGroupCount(2) = OIRGroupCount(2) + 1
Case Is <= Sheets("Lists").Cells(RptDueDate(RptDueDateR1), RptDueDate(RptDueDateC1))
OIRGroupCount(1) = OIRGroupCount(1) + 1
End Select

note: the i is incremented in a do loop.

Thanks....
 
Upvote 0
The Evaluate() code I gave you represents an actual cell-type formula, not a vba-type formula. If you want to slip VBA references into it, you'll have to do it in a way that converts the results back to cell-type formula syntax.

I can't test this for you, but maybe something like:

Code:
Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")")
 
Upvote 0
Thanks JB...

I still get the type mismatch on this code (first line)...

If Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")") < 1 Then
OIRGroupCount(2) = OIRGroupCount(2) + 1
Else
If Evaluate("NETWORKDAYS(Now()," & Cells(i, RRptHD(RRptHDC7)) & ")") <= Sheets("Lists").Cells(RptDueDate(RptDueDateR1), RptDueDate(RptDueDateC1)) Then
OIRGroupCount(1) = OIRGroupCount(1) + 1
End If
End If

I'll have to revisit this in the am.... my laptop (Vista) is having all sorts of problems... I'll be on my office pc tomorrow...

Thanks again...
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,055
Latest member
excelhelp12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top