If Row 1 = Row 2 then delete Row 2, else MsgBox

Binning

New Member
Joined
Apr 30, 2014
Messages
12
Hi there,

I'm trying to input a check into my macro. Basically the logic I'm trying to follow is:

If Row 1 = Row 2 then delete row 2,
ElseIf Row 1 <> Row 2 then Display MsgBox "Row 1 and Row 2 are different. Do you wish to continue?"
If user selects yes, resume
If user selects no, end sub and display MsgBox "Macro ended. Please correct changes manually"

Can anyone help me if this isn't too much trouble?

Thanks,
Binning
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Sorry I'm not sure about the rules on bumping here but this has now found it's way to page 6 with no reply.
 
Upvote 0
You can try this code:

Code:
Sub Match_Rows()
    

    Dim rngCell     As Range
    Dim strResponse As String
    Dim lngCount     As Long

    For Each rngCell In Range("A1:AL1")
        If rngCell <> rngCell.Offset(1, 0) Then
            lngCount = lngCount + 1
        End If
    Next rngCell
    
    If lngCount = 0 Then
        Rows(2).Delete
    Else
        strResponse = MsgBox("Row 1 and Row 2 are different. Do you wish to continue?", vbYesNo)
        If strResponse = vbNo Then
            MsgBox ("Macro ended. Please correct changes manually")
            Exit Sub
        End If
    End If
End Sub


ElseIf Row 1 <> Row 2 then Display MsgBox "Row 1 and Row 2 are different. Do you wish to continue?"
If user selects yes, resume...

When you say resume do you want to have row 2 deleted?
 
Upvote 0
For Row 2 to be deleted when the user presses yes, use the following code:

Code:
Sub Match_Rows()
    

    Dim rngCell     As Range
    Dim strResponse As String
    Dim lngCount     As Long


    For Each rngCell In Range("A1:AL1")
        If rngCell <> rngCell.Offset(1, 0) Then
            lngCount = lngCount + 1
        End If
    Next rngCell
    

    If lngCount <> 0 Then
    strResponse = MsgBox("Row 1 and Row 2 are different. Do you wish to continue?", vbYesNo)
        If strResponse = vbNo Then
            MsgBox ("Macro ended. Please correct changes manually")
            Exit Sub
        End If
    End If
    Rows(2).Delete
End Sub

Good luck!
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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