How can I modify this macro in Excel?

I would like to modify the following macro.

Sub Step3()
    Dim i As Long
    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        For i = Selection.Rows.Count To 1 Step -1
            If Selection.Cells(i, 1) = "" And (Selection.Cells(i, 2) = 0 Or _   Selection.Cells(i, 2) = "0.00") Then
                Selection.Rows(i).EntireRow.Delete
            End If
        Next i
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
End Sub

Open in new window


I have a spreadsheet with 2 columns, Column A and Column B.
Column A usually has numbers such as 12345.  Column B at times is blank or has numbers.

In the following scenario, if it finds a number, in the spreadsheet, say 99999:

99999	    0.00
    	1,898.00
    	    2.00
    	 2000.00
12345

Open in new window

In the scenario above, when it finds a number which has some 'corresponding' blank fields underneath it, yet has some
numbers in Field B.  It will assume that the last blank row, before another number begins, is the Total.  The script should then move the last number it finds in the first row and insert a 0 in the other rows.

In other words it should end up looking like this.
99999  2000.00
    	     0
    	     0
12345

Open in new window

100questionsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Sub Step4()
Dim i As Long
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
For i = Selection.Rows.Count To 1 Step -1
If Selection.Cells(i, 1) <> "" Then
    Selection.Cells(i, 2) = Total
Else
    If Selection.Cells(i + 1, 1) <> "" Then
        Total = Selection.Cells(i, 2)
    End If
    Selection.Cells(i, 2) = 0
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

Open in new window

Regards
0
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Try this:
 
Sub Step3()
Dim i As Long, j As Long
With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    For i = 1 To Selection.Rows.Count
        If Selection.Cells(i, 1) = "" Then
            Selection.Cells(i, 2) = 0
        Else
            j = i + 1
            Do Until Selection.Cells(j, 1) <> "" Or Selection.Cells(j, 2) = ""
                j = j + 1
            Loop
            Selection.Cells(i, 2) = Selection.Cells(j - 1, 2)
        End If
    Next i
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aikimarkCommented:
@100questions
Why zero the values?  It seems to me that the rows should be deleted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.