nishansingh
New Member
- Joined
- Jul 15, 2015
- Messages
- 7
First time posting I apologize in advance if question is not formatted clearly or if this post is unorthodox in any way.
This is my first time using VBA so I am not familiar with the language. I have a work assignment for which I need to copy and paste the data from several excel files (All in Same Folder) together into one new master sheet. All of the excel files have the same format. I need to copy 2 tabs from each excel worksheet, "Raw Data" and "RBC Raw Data" respectively.
So far I have figured out how to copy and paste the data from only one tab of the worksheet. Also I have done this by directly entering the path of the worksheet into my code rather then the path of the folder in which all files exist.
(Was trying to figure out how to do one file before I try making a loop that runs through all files.)
any feedback or tips are highly appreciated.
THANK YOU.
This is my code so far:
-----------------------------------------------------------------------------------------------------------------------------
Sub OpenWorkbookToPullData()
Dim path As String
path = "\\ntdisk01\imo\IMO\Valuations\TOR Credit IPV\CDS Corporates\201506\CDS File-Corporates-Jul 2.xlsm"
Dim currentWb As Workbook
Set currentWb = ThisWorkbook
Dim openWb As Workbook
Set openWb = Workbooks.Open(path)
Dim openWs As Worksheet
Set openWs1 = openWb.Sheets("Raw Data")
Set SR1 = openWs1.Range("A1:XFD1048576")
SR1.Select
Selection.Copy
currentWb.Activate
Range("A1:XFD1048576").Select
ActiveSheet.Paste
openWb.Close (False) 'closes the note book that was opened
End Sub
This is my first time using VBA so I am not familiar with the language. I have a work assignment for which I need to copy and paste the data from several excel files (All in Same Folder) together into one new master sheet. All of the excel files have the same format. I need to copy 2 tabs from each excel worksheet, "Raw Data" and "RBC Raw Data" respectively.
So far I have figured out how to copy and paste the data from only one tab of the worksheet. Also I have done this by directly entering the path of the worksheet into my code rather then the path of the folder in which all files exist.
(Was trying to figure out how to do one file before I try making a loop that runs through all files.)
any feedback or tips are highly appreciated.
THANK YOU.
This is my code so far:
-----------------------------------------------------------------------------------------------------------------------------
Sub OpenWorkbookToPullData()
Dim path As String
path = "\\ntdisk01\imo\IMO\Valuations\TOR Credit IPV\CDS Corporates\201506\CDS File-Corporates-Jul 2.xlsm"
Dim currentWb As Workbook
Set currentWb = ThisWorkbook
Dim openWb As Workbook
Set openWb = Workbooks.Open(path)
Dim openWs As Worksheet
Set openWs1 = openWb.Sheets("Raw Data")
Set SR1 = openWs1.Range("A1:XFD1048576")
SR1.Select
Selection.Copy
currentWb.Activate
Range("A1:XFD1048576").Select
ActiveSheet.Paste
openWb.Close (False) 'closes the note book that was opened
End Sub