If loop skipping criteria

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hi guys, I'm trying to write code which checks if the column "Status" in "yTable" has the string "yes" in it. if it does, i want it to do a series of things, if not, then I want it to go to a different sheet and do that. This is what I have so far.

Code:
 If "yTable[[Status]:[Status]]" = "yes" Then          ActiveSheet.ListObjects("yTable").Range.AutoFilter Field:=13, Criteria1:= _
        "yes"
        Columns("M:M").Select
    Selection.EntireColumn.Hidden = True
   ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort.SortFields. _
        Add Key:=Range("yTable[[#All],[Name]]"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
        
        Sheets("Data").Select
        Range("A1").Select
        Selection.End(xlDown).Select
        ActiveSheet.ListObjects("dtable").ListRows.Add AlwaysInsert:=True
        Sheets("Yesterday").Select
        Range("A1").Select
        ActiveSheet.ListObjects("yTable").DataBodyRange.Select


        Selection.Copy
        Sheets("Data").Select
        Range("A1").Select
        Selection.End(xlDown).Select
        
       ActiveCell.Offset(1).Select
        ActiveSheet.Paste
        
 
        
        
        Range("A1").Select
        
        
      
 
 ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort.SortFields.Add _
        Key:=Range("dTable[[#All],[Name]]"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
 
Else: Sheets("Data").Select
End If

it always breaks out of the loop and goes to the other sheet, even when it says yes clearly in the column.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Maybe...

Code:
If Application.CountIf(ActiveSheet.ListObjects("yTable").ListColumns("Status").DataBodyRange, "yes") Then
    'do something
Else
    'do other thing
End If

Hope this helps

M.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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