Sub Import()
Dim strColumn As String
Dim lngLastRow As Long
Dim WL As String
Dim path As String
Dim startdate As Date
Dim TOSexport As String
Dim findit As String
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
' .ScreenUpdating = False
End With
With ThisWorkbook.Sheets("Scratch Pad")
.Columns("A:A").Value = ThisWorkbook.Sheets("ImportedData").Columns("B:B").Value
.Columns("B:B").Value = ThisWorkbook.Sheets("ImportedData").Columns("A:A").Value
End With
ThisWorkbook.Sheets("ImportedData").Select
strColumn = "B"
lngLastRow = ThisWorkbook.Sheets("ImportedData").Cells(ThisWorkbook.Sheets("ImportedData").Rows.Count, strColumn).End(xlUp).Row
ThisWorkbook.Sheets("ImportedData").Rows("$6:$" & lngLastRow).Select
'****************************
Selection.ClearContents '*******Macro "ends" at this point - if stepping through, after this step when you click Step Into again the marco starts over
'****************************
WL = ActiveWorkbook.Name
ChDrive Range("StoreDrive").Value
path = Range("StoreDirectory").Value
startdate = Date
startdate = Application.InputBox("Enter date to be imported", "Confirm Date", FormatDateTime(startdate, vbShortDate), Type:=1)
TOSexport = Format(startdate, "yyyy-mm-dd") & "-QuoteZ.csv"
findit = Dir(TOSexport)
If Len(findit) <> 0 Then
MsgBox "Export Watchlist and rerun update"
Else
Workbooks.OpenText Filename:=path + TOSexport, Origin _
:=65001, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
, 1)), TrailingMinusNumbers:=True
Columns("A:Y").Select
Selection.copy
Workbooks(WL).Activate
Sheets("ImportedData").Activate
Columns("B:Z").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
lngLastRow = ThisWorkbook.Sheets("ImportedData").Cells(ThisWorkbook.Sheets("ImportedData").Rows.Count, strColumn).End(xlUp).Row
ThisWorkbook.Sheets("ImportedData").Range("$A$5").Value = "=INDEX('Scratch Pad'!A:B,MATCH(ImportedData!B5,'Scratch Pad'!A:A,0),2)"
'****************************
ThisWorkbook.Sheets("ImportedData").Range("$A$5:$A$" & lngLastRow).Select
Selection.FillDown
Application.DisplayAlerts = False
Workbooks(TOSexport).Close
Application.DisplayAlerts = True
Sheets("Interactive Allocation").Select
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.EnableEvents = True
End With
End If
End Sub
(fyi – I’ve attached the file containing this code and it should run through the error point if you want to test it, however, without the import file and setting up the necessary file directories it won’t run to completion.)
Bookmarks