Option Explicit
Sub ADDMONTH()
Dim a As Long
Dim CSV As String, myFilepath As String
Dim Sheet1 As Worksheet
Application.ScreenUpdating = False
'Convert CSV file to Excel and add to existing Database
myFilepath = Application.GetOpenFilename(Filefilter:=CSV)
If myFilepath = "False" Then Exit Sub
Workbooks.Open Filename:=myFilepath
'Convert to columns and set as Autofit
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 2), 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), Array(16, 1), Array(17, 1)), TrailingMinusNumbers:= _
True
Cells.Select
Selection.Columns.AutoFit
'Sort into date order
With ActiveSheet
a = .Cells(.Rows.Count, "A").End(xlUp).Row
If a < 2 Then Exit Sub
Columns("A:C").Select
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range( _
"A2:A" & a), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
End With
With ActiveSheet.Sort
.SetRange Range("A1:C" & a)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Name sheet with first and last dates in Col A
ActiveSheet.Name = "Appts ""&TEXT(MIN(C[-26]),""dd mmm yyyy"")&"" - ""&TEXT(MAX(C[-26]),""dd mmm yyyy"")"
ActiveSheet.Name = Range("AA1").Value
Range("AA1").ClearContents
ActiveSheet.Move Before:=Workbooks("TESTMOVE.xlsM").Sheets(2)
Windows("TESTMOVE.xlsm").Activate
Sheets("DATABASE").Select
Range("A1").Select
End Sub
Needless to say, the End User is adamant they "changed nothing" over the three downloads, and completely uninterested in doing anything their end.
Bookmarks