Hi,
I have a file which is in some folder.I wrote vba code as below which opens the file and activates first cell and extracts the country from filename(ABC- MEXICO BLAH BLAH 2-2-2014) and writes till the end of the data. While executing I am getting an error "Application defined or Object defined error-1004'
I have two files with different countries in the same C:\excelvba folder. I have to extract both and write the country in the first column with country as heading and country name in the remaining fields. Please help
Private Sub CommandButton1_Click()
Dim Mypath As String
Dim Column1 As String
Mypath = "C\ExcelVBA"
If Right(Mypath, 1) <> "\" Then Mypath = Mypath & "\" 'Path folder ends with '\'
MyFile = Dir(Mypath & "*.xls", vbNormal)
If Len(MyFile) = 0 Then 'If no files found says - Files not found in message box
MsgBox "Files Not Found", vbExclamation
Exit Sub
End If
Workbooks.Open Mypath
'Selection.Cells(1, 1).Select
Range("A1") = "Column1"
With Range("A2:A" & LastRow)
x = Split(s, "- ", 2)
.Value = Split(Trim(Split(ActiveWorkbook.Name, "-")(1)), " ")(0)
End With
End Sub
Bookmarks