Converting Excel Countif to VBA Code

lee08

New Member
Joined
Dec 7, 2017
Messages
7
Hi,

I need your help with converting my formula into VBA Code.Please can you help me with this code, it spring a runtime error on line 2. Why?

Excel:Formula =IF(COUNTIFS(F3:F10,"NONE_TP")=0,"",(COUNTIFS(F3:F10,"NONE_TP")))



Rich (BB code):
Sub TestPhase2
Dim ws As Worksheets<o:p></o:p>
Dim lr As Long<o:p></o:p>
Dim var1 As String<o:p></o:p>
<o:p> </o:p>
'----------------------------<o:p></o:p>
'Variable<o:p></o:p>
'----------------------------<o:p></o:p>
Sheets("DetailMapping").Select<o:p></o:p>
lr = Sheets("DetailMapping").Cells(Rows.Count,6).END(xlDown).Rows<o:p></o:p>
var1 = Range("F1").Value<o:p></o:p>
<o:p> </o:p>
'----------------------------<o:p></o:p>
'Actual Condition<o:p></o:p>
'----------------------------<o:p></o:p>
If var1 = 0 Then<o:p></o:p>
    <o:p></o:p>
    var1 =Application.WorksheetFunction.CountIfs(Range("F3:F" & lr),"CUST2-NONE")<o:p></o:p>
       <o:p></o:p>
       Else (I'm thinking this is where I'm going wrong)<o:p></o:p>
       <o:p></o:p>
    var1 =Application.WorksheetFunction.CountIfs(Range("F3:F" & lr), "")<o:p></o:p>
      <o:p></o:p>
      End If<o:p></o:p>
 End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
When I pass through it stops at If var1 = 0 Then

Error Msg: Run-Time error "13": Type mismatch
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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