Skip a blank cell

JonathanOTAX

New Member
Joined
May 10, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I am trying to filter data based on the value of one column, I have created this macro which copies the entire row to a different sheet depending on whether the value is 0 or >0. This works fine if the data set is complete but the issue is when there are blank cells, this macro stops as soon as it hits a blank, I want it to ignore the blank and carry on.
Thank you.

VBA Code:
Sub copyrows()
 Dim tfCol As Range, Cell As Object
 
 Set tfCol = Range("G2:G999")
 
 For Each Cell In tfCol
 
 If IsEmpty(Cell) Then
 Exit Sub
 End If
 
 If Cell.Value = 0 Then
 Cell.EntireRow.Copy
 Sheet4.Select
 ActiveSheet.Range("A65536").End(xlUp).Select
 Selection.Offset(1, 0).Select
 ActiveSheet.Paste
 End If
 
 If Cell.Value > 0 Then
 Cell.EntireRow.Copy
 Sheet2.Select
 ActiveSheet.Range("A65536").End(xlUp).Select
 Selection.Offset(1, 0).Select
 ActiveSheet.Paste
 End If
 
 Next
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi & welcome to MrExcel.
How about
VBA Code:
   For Each Cell In tfCol
      
      If Cell = "" Then
      ElseIf Cell.Value = 0 Then
         Cell.EntireRow.Copy
         Sheet4.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      Else
         Cell.EntireRow.Copy
         Sheet2.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      End If
      
   Next
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
   For Each Cell In tfCol
     
      If Cell = "" Then
      ElseIf Cell.Value = 0 Then
         Cell.EntireRow.Copy
         Sheet4.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      Else
         Cell.EntireRow.Copy
         Sheet2.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      End If
     
   Next
Excellent, that works perfectly, thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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