Hi all. Bit rusty on this VBA stuf.
1. I need to copy a range from CSV file and hoping to do that by going directly to the master workbook.
2. Close CSV workbook only.
3. Activate master workbook.
the macro runs but have to (2) manually and wish to eliminate this manual task.
The macro is run from master workbook and both files are in the same folder on a server. It is Excel 13 that I am using.
1. I need to copy a range from CSV file and hoping to do that by going directly to the master workbook.
2. Close CSV workbook only.
3. Activate master workbook.
the macro runs but have to (2) manually and wish to eliminate this manual task.
The macro is run from master workbook and both files are in the same folder on a server. It is Excel 13 that I am using.
Code:
Sub OpenCSV_CopyPaste()
'
' Copy_Paste_CSV Macro
' To open CSV file and copy to master WB
Dim wb As Workbook: Set wb = ThisWorkbook
Dim cN As String
cN = InputBox("Enter CSV name without '.csv' ", "CSV Filename!")
cN = cN & ".csv"
'
'Opens CSV file for weekly weather data
Workbooks.OpenText Filename:="J:\Te Maunga ops\Easyweather\CSV EW\" & cN, _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 4), 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), Array(18, 1), Array(19, 1)), TrailingMinusNumbers:= _
True
'Selects and copies data fromCSV
Range("B2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
[COLOR=#0000CD][B] 'Paste directly into master workbook
Windows(wb).Sheets("CSV").Range("B" & Rows.Count).End(xlUp).Offset(1).Paste
ActiveWorkbook.Close[/B][/COLOR]
'Activates master weather WB & pastes to end of data set
'Windows("170116 weather history .xlsm").Activate
'Sheets("CSV").Select
'Range("B" & Rows.Count).End(xlUp).Offset(1).Select
'ActiveSheet.Paste
End Sub