VBA autofilter returns blank cells then jump code

Blunder1

Active Member
Joined
Jun 2, 2010
Messages
250
Hi,

In my vba i need to copy data. I do this using the auto filters. However, when it returns no data i need it to jump the next bit of code by ising an IF statement.

I have tried a few methods, the below being the last but cannot get it recognise no data returned ( i have names sheets 'we' and 'wf' ):-

Code:
we.UsedRange.AutoFilter field:=4, Criteria1:="NOK"
Set rng = we.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible)
If Not rng Is Nothing Then
we.Range("a1:a" & Cells(Rows.Count, "a").End(xlUp).Row).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=wf.Range("a65536").End(xlUp).Offset(1, 0)
End If

Thanks in advance

Blunder
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
.offset select the range next to active cell hence it's not working

you need to set a range first, then copy filtered range. Ex -

Code:
 Set Rng = .Range("B2:B" & .Range("B" & .Rows.Count).End(xlUp).Row)
Rng.SpecialCells(xlCellTypeVisible).Copy ShTarget.Range("A1")

Hope it helps
 
Upvote 0
thank you G2K. It didn't work ooutright, but pointed me in teh right direction.

Thank you again

Blunder
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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