Userform disappear after copy

seba64

New Member
Joined
Apr 24, 2016
Messages
32
I have a userform with a button. On click that button, the code copy sheet1 to sheet2 and then select some rows.

When the code execute the next sentence, excel show a message saying something like:
[Can´t enter on interruption mode]
after that, the userform disappear

The message disappear if add the code: Application.DisplayAlerts = False
but the userform disappears anyway

The sentence

Code:
    Sheets(nombHoja).Copy after:=Sheets(Sheets.Count)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub duplicate(nombHoja, Optional nomb = "")
    Dim Hoja2
    ThisWorkbook.Activate
    If nomb = "" Then nombHoja2 = nombHoja & " (2)" Else nombHoja2 = nomb
    Application.DisplayAlerts = False
    On Error Resume Next
    Sheets(nombHoja2).Delete
    On Error GoTo 0
    Sheets(nombHoja).Copy after:=Sheets(Sheets.Count)
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
All code:
Code:
Private Sub CommandButton6_Click()

    Dim MyRange As Range
    Dim cell As Object
    
    nombHoja = "Hoja1": nomb = "Hoja2"
    Dim Hoja2
    ThisWorkbook.Activate
    If nomb = "" Then nombHoja2 = nombHoja & " (2)" Else nombHoja2 = nomb
    Application.DisplayAlerts = False
    On Error Resume Next
    Sheets(nombHoja2).Delete
    On Error GoTo 0
    Sheets(nombHoja).Copy after:=Sheets(Sheets.Count)
    If nomb <> "" Then Sheets(Sheets.Count).Name = nomb
    Application.DisplayAlerts = True




    Sheets("Hoja2").Select
    Rng1 = Range("A1:A75")
    
    For Each cell In Range("A1:A75")
        cell2 = cell.Offset(0, 1)
        If cell.Value = TextBox1.Text And cell2 = TextBox2.Text Then
            If MyRange Is Nothing Then
                Set MyRange = Range(cell.Address)
            Else
                Set MyRange = Union(MyRange, Range(cell.Address))
            End If
        End If
    Next
    If Not MyRange Is Nothing Then
        MyRange.Select
        Selection.EntireRow.Select
    End If

'    invSelecccion

    Dim rng As Range, RngSelect As Range

    With ActiveSheet
        .UsedRange
        If Selection.Address = .UsedRange.Address Then
            ''' ???  do nothing???
        Else
            For Each rng In .UsedRange
                If Intersect(rng, Selection) Is Nothing Then
                    If RngSelect Is Nothing Then
                        Set RngSelect = rng
                    Else
                        Set RngSelect = Union(RngSelect, rng)
                    End If
                End If
            Next
            If Not RngSelect Is Nothing Then
                RngSelect.Select
            End If
        End If
    End With

' Delete selection
    Selection.Delete
    Range("A1").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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