I created an Import button which should import data from another opened Excel file, but instead I'm having the following issue. It is 2013 office version.
I have no idea what is wrong with it and would appreciate some advice.
Screenshots:
Code of function responsible for importing data, which should take data from open excel file and paste it to another one:
Sub ImportORT()
Dim Rng2 As Range
Dim wbk As Workbook
Set wbk = ThisWorkbook
Dim RowCounter As Long
Dim clipboard As MSForms.DataObject
Dim str1 As String
Application.ScreenUpdating = False
Sheets("Data").Select
Sheets("Data").Cells.NumberFormat = "@"
Range("A1").Select
On Error GoTo Nopaste
Windows("mvrt.xlsx").Activate
ActiveSheet.Cells.Select
'Range("A1:U16").Select
Selection.Copy
Windows("Offsite Macro_2016_v20.xlsm").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False, NoHTMLFormatting:=True
Rows("1:1").Delete Shift:=xlUp
'Range("A:A").Delete Shift:=xlLeft <--- kasowanie pierwszej kolumny (ma sens tylko jak wklejamy ze strony)
'changed:
Set Rng2 = Application.Intersect(ActiveSheet.UsedRange, Range("A:U"))
Rng2.SpecialCells(xlCellTypeVisible).Copy
Sheets("MVRT").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets("MVRT").Activate
Range("A:U").Columns.AutoFit
Range("A1:U1").AutoFilter
Application.Goto Reference:=Range("A1"), Scroll:=True
'-------------------------------------------
'NEW:
'change column format
Columns("U:U").Select
Selection.NumberFormat = "General"
'remove identical rows
RowCounter = wbk.Sheets("MVRT").Cells(Rows.Count, 2).End(xlUp).Row
wbk.Sheets("MVRT").Range("$A$1:$m$" & RowCounter).RemoveDuplicates Columns:=Array(2, 3, 9, 10, 11, _
12, 13), Header:=xlYes
'set formula
Range("U2").Select
ActiveCell.FormulaR1C1 = "=IF(COUNTIF(C[-14],RC[-14])>1,1,0)"
Range("U2").Select
If Range("A:A").Rows.End(xlDown).Row > 2 Then
Selection.AutoFill Destination:=Range("U2:U" & Range("A:A").Rows.End(xlDown).Row)
End If
'sort by duplicates
Range("U1").Value = "duplicated"
Columns("A:U").Sort Key1:=Range("U1"), Order1:=xlDescending, key2:=Range("C1"), Order2:=xlAscending, key3:=Range("B1"), Order3:=xlAscending, Header:=xlYes
'-------------------------------------------
Sheets("Data").Cells.Delete
Sheets("Control").Activate
Application.Goto Reference:=Range("A1"), Scroll:=True
Application.ScreenUpdating = True
MsgBox "Codes Imported", vbInformation, "Codes Imported"
Exit Sub
Nopaste:
'------------------------------------
'NEW:
Application.ScreenUpdating = True
'------------------------------------
Sheets("Control").Activate
Application.Goto Reference:=Range("A1"), Scroll:=True
MsgBox "No Data To Paste", vbExclamation, "No Data To Paste"
Exit Sub
End Sub