Skip cells that equal 0 - IF, Loop

mozza90

New Member
Joined
Mar 19, 2015
Messages
32
Hi,

I have the below code which currently check a cell for a value greater than 0, if it is, it copies the figure into another sheet. The code loops until the last row of data.

It has now arisen that sometimes the figure in the Data cell can equal 0. Is there a way to skip the cell if it contains 0 and then continue to check the remaining data?

Code:
Do Until ActiveCell.Value = ""
          Data = ActiveCell.Offset(0, 12).Value
        
            If Data > 0 Then
                ActiveCell.Offset(0, 12).Select
                Range(ActiveCell.Offset(0, -12), ActiveCell).Select
                Selection.copy
                Sheet2.Select
                Range("A1048575").Select
                Selection.End(xlUp).Offset(1).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
             End If

            ActiveCell.Offset(0, 13).Select
            ActiveCell.FormulaR1C1 = "Client A"
            
            
            Sheet1.Select
            ActiveCell.Offset(1, 0).Select
            
     Loop
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Do Until ActiveCell.Value = ""
          Data = ActiveCell.Offset(0, 12).Value
        
            If Data > 0 Then
                ActiveCell.Offset(0, 12).Select
                Range(ActiveCell.Offset(0, -12), ActiveCell).Select
                Selection.copy
                Sheet2.Select
                Range("A1048575").Select
                Selection.End(xlUp).Offset(1).Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
             [COLOR=#ff0000]End If <-- delete this line[/COLOR]

            ActiveCell.Offset(0, 13).Select
            ActiveCell.FormulaR1C1 = "Client A"
            
            [COLOR=#ff0000]End If <-- add this line[/COLOR]

            Sheet1.Select
            ActiveCell.Offset(1, 0).Select
            
     Loop
 
Upvote 0
Thanks Fluff. This stops my error, but it still copies the data when the cell = 0. Is there a way for the code to skip over 0's and continue to the next cell in the range?
 
Upvote 0
Firstly you made no mention of any errors.
Secondly I misread your question.
You need to keep the code as it was & that should be ok. If you are getting any error messages, what are they & what line is highlighted.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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