if cell does not contain value skip then go to next code

Leksv0j

New Member
Joined
Sep 15, 2017
Messages
22
Hi
Would someone be able to help with the VBA code if cell does not contain "data" the go to next code?
Eg: skip cell does not contain "Asset" the go to next code cell contains "Same"?
I have the below code which I use to generate cell range contains "asset"
ActiveSheet.Range("$A$1:$AA$76").AutoFilter Field:=22, Criteria1:= _"=*Asset*", Operator:=xlAnd
''''' do stuff'''''''''''
i want the code above to if not found go to next code
Sub within_PO()
ActiveSheet.Range("$A$1:$AA$76").AutoFilter Field:=22, Criteria1:= _"=*Same*", Operator:=xlAnd
Thank you so much

<tbody>
</tbody>
 
Could you run this
Code:
Sub TASKSHEET()

    Dim UsdRws As Long
    Dim w As Workbook

    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Columns("V:V").Select
    ActiveSheet.Range("V1:V" & UsdRws).AutoFilter Field:=22, Criteria1:="=*Asset*"
    MsgBox Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count
End Sub
This will say how many visible cells there are
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Could you run this
Code:
Sub TASKSHEET()

    Dim UsdRws As Long
    Dim w As Workbook

    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Columns("V:V").Select
    ActiveSheet.Range("V1:V" & UsdRws).AutoFilter Field:=22, Criteria1:="=*Asset*"
    MsgBox Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count
End Sub
This will say how many visible cells there are

my result is 82. 81"Asset* found visible.
 
Upvote 0
Apologies, I should have asked you to run that when there are no values of "Asset" to be found.
 
Upvote 0
I did try that too and the result is 1. Row header only

In that case I'm not sure what the problem is. If you get a value of 1 when there is only the header row (ie no values of "Asset") then the red part of this line
Code:
    If [COLOR=#ff0000]Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count = 1[/COLOR] Then GoTo Xit
returns true & it should goto Xit

Are you saying that this is not happening?
 
Upvote 0
In that case I'm not sure what the problem is. If you get a value of 1 when there is only the header row (ie no values of "Asset") then the red part of this line
Code:
    If [COLOR=#ff0000]Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count = 1[/COLOR] Then GoTo Xit
returns true & it should goto Xit

Are you saying that this is not happening?

it counts the row header that is why i get a value of 1. right?
yes it returns true and should go to Xit but it does not go there and still proceed with the next statement of code.
 
Upvote 0
it counts the row header that is why i get a value of 1. right?
Yes that's correct.

The question is, why is it then going to the next line rather than the GoTo?
And unfortunately, the answer is

I haven't got a clue:confused:
 
Upvote 0
i guess this is working now. injecting this code below.

Code:
Dim UsdRws As Long    Dim w As Workbook


    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Columns("V:V").Select
    ActiveSheet.Range("V1:V" & UsdRws).AutoFilter Field:=22, Criteria1:="=*Asset*"


    

     If Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count = 1 Then GoTo Xit

i will try this on different sheets i will received and let you know.
 
Upvote 0
i guess this is working now. injecting this code below.

Code:
Dim UsdRws As Long    Dim w As Workbook


    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Columns("V:V").Select
    ActiveSheet.Range("V1:V" & UsdRws).AutoFilter Field:=22, Criteria1:="=*Asset*"


    

     If Range("V1:V" & UsdRws).SpecialCells(xlVisible).Cells.Count = 1 Then GoTo Xit

i will try this on different sheets i will received and let you know.

The code is working fine now. thanks you so much Fluff!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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