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

Leksv0j

New Member
Joined
Sep 15, 2017
Messages
22
[TABLE="width: 64"]
<tbody>[TR]
[TD="class: xl65, width: 64"]Hi[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]Would someone be able to help with the VBA code if cell does not contain "data" the go to next code?[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]Eg: skip cell does not contain "Asset" the go to next code cell contains "Same"?[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl65"]I have the below code which I use to generate cell range contains "asset"[/TD]
[/TR]
[TR]
[TD]ActiveSheet.Range("$A$1:$AA$76").AutoFilter Field:=22, Criteria1:= _"=*Asset*", Operator:=xlAnd[/TD]
[/TR]
[TR]
[TD]''''' do stuff'''''''''''[/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"]i want the code above to if not found go to next code[/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"]Sub within_PO()[/TD]
[/TR]
[TR]
[TD="class: xl66, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl66, width: 64"]ActiveSheet.Range("$A$1:$AA$76").AutoFilter Field:=22, Criteria1:= _"=*Same*", Operator:=xlAnd[/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD]Thank you so much[/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl68"][/TD]
[/TR]
[TR]
[TD="class: xl67, width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl65"][/TD]
[/TR]
</tbody>[/TABLE]
 
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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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