Hi,
have the code below working only issue is when click import open path select file and it opens again, what I am doing now when open again click cancel and fine, but wonder why open twice the file dialog picker:
here is the code:
thank you
have the code below working only issue is when click import open path select file and it opens again, what I am doing now when open again click cancel and fine, but wonder why open twice the file dialog picker:
here is the code:
VBA Code:
Sub ImportRawData()
Dim c As Long
Dim Col As Variant
Dim Filename As String
Dim Filepath As Variant
Dim rngBeg As Range
Dim rngEnd As Range
Dim rngDst As Range
Dim rngSrc As Range
Dim rowsize As Long
Dim wkbDst As Workbook
Dim wkbSrc As Workbook
Dim vFile
Dim fd As FileDialog
Dim newFile As String, fName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
' Change initial folder as needed or store it in a cell and reference that
fd.InitialFileName = "W:\NCL\NAVCOM\AP63A\NAVCOM\AP63A\VANCOUVER\IMPORT FILES"
'fd.AllowMultiSelect = True
FilePicked = fd.Show
vFile = Application.GetOpenFilename("CSV Files(*.csv),*.csv", , "please select a file", MultiSelect:=False)
Set wkbDst = ThisWorkbook
Set rngDst = wkbDst.Worksheets("EFT Summary").Range("A5:F5")
Filepath = "C:\Users\jose.rossi\AppData\Roaming\Microsoft\Templates\Primus Batch EFT.....xltm"
Filename = "apcbtclz.csv"
On Error Resume Next
Set wkbSrc = Workbooks(Filename)
If Err = 9 Then
If Filepath <> "" Then ChDir Filepath Else ChDir ThisWorkbook.Path
'Filename = Application.GetOpenFilename("Excel Workbooks, *.xlsx")
If Filename = "False" Then Exit Sub
Set wkbSrc = Workbooks.Open(Filename)
End If
On Error GoTo 0
' Clear previous data.
'rngDst.Resize(rngDst.Parent.UsedRange.Rows.Count).ClearContents
' Import the data.
With wkbSrc.Worksheets("apcbtclz").UsedRange
' Step through the source data columns.
For Each Col In Array("AW", "BO", "BB", "AX", "X", "CH")
' Data starts on row 1.
Set rngBeg = .Parent.Cells(1, Col)
' Find the row where the data ends in this column.
Set rngEnd = .Parent.Cells(Rows.Count, Col).End(xlUp)
' Number of rows in this column.
rowsize = rngEnd.Row '- rngBeg.Row
If rowsize > 0 Then
Set rngSrc = .Parent.Range(rngBeg, rngEnd)
rngDst.Offset(0, c).Resize(rowsize, 1).Value = rngSrc.Value
End If
' Increment the column offset.
c = c + 1
If c = 6 Then Let c = 7
Next Col
End With
wkbSrc.Close (True)
End Sub
thank you