I want to import a CSV file and save it in a Sheet in my existing excel workbook
Sub ImportRawData()
'Import Raw data
Const strFileName = "C:\Data\RawData.xlsx" '<<--Change this secotion for all region
Dim wbkS As Workbook
Dim wshS As Worksheet
Dim wshT As Worksheet
'Delete any Raw Data if present previously.
Application.DisplayAlerts = False
For Each Sheet In ActiveWorkbook.Worksheets
If Sheet.Name = "RawData" Then
Sheet.Delete
End If
Next Sheet
Application.DisplayAlerts = True
'Insert RawData to new sheet
Set wshT = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Set wbkS = Workbooks.Open(Filename:=strFileName)
Set wshS = wbkS.Worksheets(1)
wshS.UsedRange.Copy Destination:=wshT.Range("A1")
wbkS.Close SaveChanges:=False
ActiveSheet.Name = "RawData"
'Save the Last Row and Last Column of raw Data into a varible
Dim lC As Long
Dim LR As Long
With ThisWorkbook.Sheets("RawData")
lC = .Cells(1, .Columns.Count).End(xlToLeft).Column
LR = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Secretly save the values in a location in Automation sheet invisible to users.
Sheets("Automation").Select
ThisWorkbook.Sheets("Automation").Range("B34").Value = lC
ThisWorkbook.Sheets("Automation").Range("B36").Value = LR
Sheets("Automation").Select
End Sub
Sub ImportRawData()
'Import Raw data
Const strFileName = "C:\Data\RawData.xlsx" '<<--Change this secotion for all region
Dim wbkS As Workbook
Dim wshS As Worksheet
Dim wshT As Worksheet
'Delete any Raw Data if present previously.
Application.DisplayAlerts = False
For Each Sheet In ActiveWorkbook.Worksheets
If Sheet.Name = "RawData" Then
Sheet.Delete
End If
Next Sheet
Application.DisplayAlerts = True
'Insert RawData to new sheet
Set wshT = Worksheets.Add(After:=Worksheets(Worksheets.Count))
Set wbkS = Workbooks.Open(Filename:=strFileName)
Set wshS = wbkS.Worksheets(1)
wshS.UsedRange.Copy Destination:=wshT.Range("A1")
wbkS.Close SaveChanges:=False
ActiveSheet.Name = "RawData"
'Save the Last Row and Last Column of raw Data into a varible
Dim lC As Long
Dim LR As Long
With ThisWorkbook.Sheets("RawData")
lC = .Cells(1, .Columns.Count).End(xlToLeft).Column
LR = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Secretly save the values in a location in Automation sheet invisible to users.
Sheets("Automation").Select
ThisWorkbook.Sheets("Automation").Range("B34").Value = lC
ThisWorkbook.Sheets("Automation").Range("B36").Value = LR
Sheets("Automation").Select
End Sub