vba: logical error . Output is not correct

shrinivasshweta

New Member
Joined
Dec 29, 2016
Messages
18
Code:
arr1 = Array("m", "n", "o", "p")
    
    With Worksheets("Sheet1")
    With .Range("B3", .Cells(Rows.Count, "M").End(xlUp))
    celltxt1 = Sheet1.Range("b:b").Text
    If InStr(1, celltxt1, " *abc* ") Then
    'do nothing
        Else: For Each cell In Range("M:M")
                   If cell.Value = vbNullString Then
                   'do nthing
                   Else:
                     For Each elem In arr1
                       a = a + WorksheetFunction.Sum(WorksheetFunction.CountIf(.Columns(7), elem))
                       Next elem
                  End If
               Next cell
           End If
    
    End With
    End With

I want to run this macro with the above logic.
There is no compile time error but i am getting the output as
a
0


I don;t know whats wrong with this logic.
Can someone please help me out?
Thank you so much in advance. :)
 
Last edited by a moderator:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I tried with this logic too: still same reply



Code:
search = " *abc* "
With Worksheets("Sheet1")
With .Range("B3", .Cells(Rows.Count, "M").End(xlUp))


    If (IsError(Application.VLookup(search, Sheet1.Range("B:B"), 3, False))) Then
    For Each cell In Range("M:M")
              If IsEmpty(cell) = False Then
                 For Each elem In arr1
                   a = a + WorksheetFunction.Sum(WorksheetFunction.CountIf(.Columns(7), elem))
                   Next elem
              End If
           Next cell
       End If
please help me out !
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,804
Members
449,468
Latest member
AGreen17

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