Msg box error.

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,

I am facing 2 error messages in my code.

The first time I press match portal, the error is at this line:
Rich (BB code):
wsDestination.UsedRange.Clear,

Maybe this is due to the destination sheet is not created yet. But the second time I press match portal without doing anything the code runs and gives the correct result. How do I avoid this error.?

The second error is that when the code is running it displays a msgbox in the middle of the code and once again at the end of the code. That is twice while running the code. The msgbox line is written only once in the end of the code. I wonder why...
Need your expert help to make these 2 errors vanish.
Two Error messages to remove.xlsm
 
Rich (BB code):
Set wsDestination = Nothing                                            ' Assign DestinationSheet to wsDestination
    On Error Resume Next                                                                    ' Bypass error generated in next line if sheet does not exist
           Set wsSource = Sheets(SourceSheet)                                                 ' Assign SourceSheet to wsSource
        Set wsMatched = Sheets(MatchedSheet)                                                ' Assign MatchedSheet to wsMatched
     Set wsMismatches = Sheets(MismatchesSheet)                                             ' Assign MismatchesSheet to wsMismatches
    On Error GoTo 0                                                                         ' Turn Excel error handling back on
'
' Create DestinationSheet if it doesn't exist
    If Not wsDestination Is Nothing Then DestinationSheetExists = True                      ' Check to see if the DestinationSheet exists
    If DestinationSheetExists = False Then                                                  ' If DestinationSheet does not exist then ...
        Sheets.add(after:=wsSource).Name = DestinationSheet                                 '   Create the DestinationSheet after the Source sheet
        Set wsDestination = Sheets(DestinationSheet)                                        '   Assign the DestinationSheet to wsDestination
    End If
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You forgot to resume Set wsDestination = Sheets(DestinationSheet), you need it if for some reason the sheet "Edited Portal" already exists.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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