Hello
I've have a userform , and when i click on button to update a sheet , execute the module above and it's working ,it opens a file explorer to choose the file i select the file , it clears the sheet , and it updates the values.
The problem is , if i cancel the update in the file explorer , it gives me the MsgBox " Actualização cancelada" but also clears the sheet
How can i prevent , if i cancel , to clear the sheet ?
I want is , if i cancel , to not update e sheet1 remains the same before clicking the button
Thank you in advance
I've have a userform , and when i click on button to update a sheet , execute the module above and it's working ,it opens a file explorer to choose the file i select the file , it clears the sheet , and it updates the values.
The problem is , if i cancel the update in the file explorer , it gives me the MsgBox " Actualização cancelada" but also clears the sheet
How can i prevent , if i cancel , to clear the sheet ?
I want is , if i cancel , to not update e sheet1 remains the same before clicking the button
Thank you in advance
VBA Code:
Sub copy_worksheet()
On Error GoTo Cancel
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Sheet1").Range("A2:D5000").Clear
Set Source_workbook = Workbooks.Open(Application.GetOpenFilename(FileFilter:="Excel Files,*.xls*"))
Source_workbook.Sheets("Sheet1").Range("A2:D5000").Copy _
ThisWorkbook.Sheets("Sheet1").Range("A2:D5000")
Source_workbook.Close SaveChanges:=False
Application.ScreenUpdating = True
MsgBox "Lista de Impressoras actualizada "
Exit Sub
If Err.Number > 0 Then GoTo Cancel
Cancel:
MsgBox " Actualização cancelada"
End Sub