Help with a marco

baldi

Board Regular
Joined
Sep 15, 2009
Messages
159
I have a marco that copy's the numbers from A1 and B1. then pastes them on another sheet. I want to write into the marco that if "A1 does not equal B1" the marco stops working until the 2 cells equal each other.

thanks in advance for all the help.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If your using a looping script then use something like this:

Code:
Sub Copy_To_Sheet_Two()
Application.ScreenUpdating = False
'Modified 4-3-18 11:40 PM EDT
Dim i As Long
Sheets(1).Activate
Dim Lastrow As Long
Dim Lastroa As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Lastrowa = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1
    For i = 1 To Lastrow
        If Cells(i, 1).Value = Cells(i, 2).Value Then
            Cells(i, 1).Resize(, 2).Copy Sheets(2).Cells(Lastrowa, 1): Lastrowa = Lastrowa + 1
        Else
            MsgBox "Values do not match" & vbNewLine & "I have stopped the script": Exit Sub
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
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